Automatically zooming/panning axis in response to user interaction with opposing axis


I have a line graph with a pannable/zoomable Y-axis and a non-user-alterable X-axis. I’d like the X-axis to automatically pan and zoom to show as much data as possible as the user moves around on the Y-axis. That is, given a graph like this:

Zooming in to 1-2 on the Y-axis would cause the X-axis to scale to something like this:

What’s the best way to go about this? It occurs to me that I can use setRangeWithMinimum:andMaximum: to move the axis around in reaction to sChartDidFinishZooming:/sChartDidFinishPanning: but do I have to go all the way back out to my datasource to determine the min/max based on the new Y-axis range?


For anyone finding this from Google and wondering what’s next: as of right now, the chart delegate goes back out to the datasource to ask it what the range is. It’s not a perfect solution; the datasource is SQLite-backed and I’m dealing with quite a volume of data, so I can’t rescale the data as quickly as I’d like to – ideally, the rescaling would be triggered by sChartIsZooming:/sChartIsPanning: wirth a minimum of 0.1s between updates – but it is functional.


Hi Samuel,

The implementation you described is an appropriate solution to your problem.

However, you may want to look at the “gesturePinchAspectLock” property on your chart as it will cause a similar effect and you don’t need to involve your datasource. For this property to work both of your axes must be zoom enabled.

Kind Regards,
Andrew Polkinghorn