Fitting yAxis after changing the range on xAxis


#1

Hello,

I’m trying to display a financial candle chart on iOS, with a control to select predefined time ranges (from a few months to a few years), for quick access. I managed to set the range of the xAxis quite easily, using setRange:withAnimation:, but I cannot find anything that would help me adjusting the yAxis to fit the data for this range to the full height. So for now, the yAxis is still keeping its full height matching the full range of data.

One obvious (and brute force) solution is to manually scan the data to find the min/max, but I was hoping there would be a simpler way…?


#2

Hi there,

For controlling the y-axis range you have two main options, you can allow the autoCalculatedRange property to remain as true by default. This will mean the range is auto calculated based on the maximum and minimum values from your given data set. Alternatively you can set this to false which will enable you to make use of the defaultRange property and setRange:withAnimation: method which are available for both axes.

Unfortunately given the situation you’ve described above, it will be down to you for calculating which data points are the minimum and maximum within your x-axis range in order to set your y-axis range as we don’t currently provide API that assists with this.

Let me know if you have any questions.

Kind regards,

Matt / iOS Developer 


#3

That’s what I was afraid of, but I’ll definitely try that! There’s one other issue that I ran into when playing with ranges: if I set a range on the xAxis right after doing a reloadData / redrawChart, it’s plain ignored. Usually, it will only work when in reaction to a user action, after the chart has been drawn and reloaded already.

Any hint on how to set an initial range when loading the data?

Thanks!


#4

I’d recommend you call redrawChart after updating the range instead of before it. You can also set the defaultRange during loading which will set the initial range that gets displayed when the chart is finished loading.