How to implement Zoom-in and Zoom-Out with Core-Plot line chart on iPhone?

Appbrain picture Appbrain · Feb 15, 2010 · Viewed 10.1k times · Source

Is it possible to implement Zoom-in and Zoom-Out with Core-Plot Chart component on iPhone? If so please suggest me how to do it?

Thanks in advance.

Answer

Felix Khazin picture Felix Khazin · Feb 24, 2010

Yes, The way I do it is by adjusting the PlotSpace like so (probably not the best solution, but the best one i could come up with):

-(void)zoomOut 
{
    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;

    graphScaleX+=5;
    graphScaleY+=5;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:plotSpace.xRange.location length:CPDecimalFromFloat(graphScaleX)];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:plotSpace.yRange.location length:CPDecimalFromFloat(graphScaleY)];
}

-(void)zoomIn
{
    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;

    graphScaleX-=5;
    graphScaleY-=5;

    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:plotSpace.xRange.location length:CPDecimalFromFloat(graphScaleX)];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:plotSpace.yRange.location length:CPDecimalFromFloat(graphScaleY)];
}