IOS Charts - set the minimum y-axis range

I use the awesome iOS Charts library ( https://github.com/danielgindi/ios-charts ) and it’s hard for me to find anything to support this behavior in the documentation. I would like to make the y axis always display a range from 0-35. Currently, if I have only one data record, say (0, 9), the y axis will display its range as 0-9. However, when I add another entry to (1, 32), suddenly I see the top of the graph at 35.

There are three methods that look promising (because they are related), but they do not quite provide the type of behavior I am looking for.

1: Chart.setVisibleYRangeMaximum (if only it was Minimum ...)

2: Chart.setVisibleXRangeMaximum (useless again ...)

3: Chart.setVisibleXRangeMinimum (now when is your YRange cousin ?!)

Anyway, where I am. I read the documentation, but to no avail. Help me SO?

+5
source share
3 answers

customAxisMin Deprecated in recent graphs.

Use the axisMinValue property instead

+9
source

See the properties below. Must be able to solve your problem.

 /// A custom minimum value for this axis. /// If set, this value will not be calculated automatically depending on the provided data. /// Use resetCustomAxisMin() to undo this. /// Do not forget to set startAtZeroEnabled = false if you use this method. /// Otherwise, the axis-minimum value will still be forced to 0. public var customAxisMin = Double.NaN /// Set a custom maximum value for this axis. /// If set, this value will not be calculated automatically depending on the provided data. /// Use resetCustomAxisMax() to undo this. public var customAxisMax = Double.NaN /// if true, the y-label entries will always start at zero public var startAtZeroEnabled = true 

For instance:

 _chartView.leftAxis.customAxisMax = 35; _chartView.leftAxis.customAxisMin = 0; 

or _chartView.leftAxis.startAtZeroEnabled = YES;

+8
source

For charts 3 (tested on charts 3.0.2) this works:

 chartView.leftAxis.axisMinimum = 0 

By default, there is also rightAxis (at least for histograms), and the grid will not be aligned unless you also set:

 chartView.rightAxis.axisMinimum = 0 

Note. At first I wrote this as a comment, but I think it should be an answer that will be easier to find for people who get here from Google.

+2
source

All Articles