Reload data but preserve X axis range



I am displaying a time series and providing different data sources depending on the zoom level on the X axis. So as the user zooms in the chart, I provide more data points to get a finer-grained chart. And I do the opposite when the user zooms out.

This works very well, except that I can’t get axis reloading (or not) working properly.

Here’s how I do it:

- (void)sChartDidFinishZooming:(ShinobiChart *)chart
    if( needsToSwitchDataset )
// chart.autoCalculateAxisRanges = NO;
        [chart reloadData];
        [chart redrawChart];

If I don’t set autoCalculateAxisRanges to NO (commented line in my example), the X axis resets to its initial range after reloading the data. If I do set it to NO, the X axis range is preserved just as I want it. However, the Y axis does not adjust to the new data.

Is there a way to set auto calculation of axis range on a per-axis basis instead of the whole chart? If not, what would be the best way to preserve the X axis range after zooming?




One option is to create a global x-axis range object that you update as required. During a reload, if this is not nil you can then apply it in the renderFinished delegate method.


I have tried this, but it seems that auto calculation of axis ranges overrides the range I set in renderFinished. I also tried setting the range in didFinishLoadingData, did not work either.

Now I’m thinking of leaving autoCalculateAxisRanges to NO and find a way to calculate the range of my Y axis manually. How could I do that?


Hi Bourquep,

Take a look at my post on this thread here. The same method I suggest should apply, but just for your Y-axis.