This question is an continuation of a previous question:
How to select a Column series Bar in code
In that question it has been established that in order to select a bar in code you need to use the delegate and set selected on the current point to YES
. Then you need to call -reloadData
& -redrawChart
Which is working OK.
Now, if you have a large enough data set I need to set the Default Range to ensure each bar is not too narrow and shows that there are more so the last one is half shown.
SChartRange *range = [[SChartNumberRange alloc] initWithMinimum:@(-0.5) andMaximum:@(8)];
[self.chartView.xAxis setDefaultRange:range];
The values are a bit odd but if min is 0 then the first bar is only half shown. But this gives a range of 9.5 which seems to look ok. I'm actually working this out based on the width of chart view and a good size for each bar - about 40 points seems to work.
Anyway, now that I am able to select the next point (in code), I now may also need to scroll the chart to make sure that the selected bar is visible. Also I need to not scroll if it is currently visible.
Remember that because I'm calling -reloadData
& -redrawChart
I cannot just update the chart's range, it seems I have to set the default range.
I have tried getting the current range, checking if the next selected bar index is in side this range and calculating the new range but this is not working for me in all cases - it's actually quite bizarre what happens here... e.g. for the last point I have to set it so the range is 7.5 not 9.5 like the others...
Is there a recommended way to do this? I was hoping for a method like scroll index visible kind of method on the chart but cannot find anything.