Question

I have 2 scatter plots in a single plot. Both the plots have the same x-axis but the y scale is different. So I have created a new plot space.

CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;

CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *) graph.newPlotSpace;
newPlotSpace.identifier = @"Fund PlotSpace";
[graph addPlotSpace:newPlotSpace];

// 2 - Create the two plots
CPTScatterPlot *aaplPlot = [[CPTScatterPlot alloc] init];
aaplPlot.delegate = self;
[graph addPlot:aaplPlot toPlotSpace:plotSpace];

CPTScatterPlot *fdPlot = [[CPTScatterPlot alloc] init];
fundingPlot.delegate = self;
[graph addPlot:fdPlot toPlotSpace:newPlotSpace];

I also have enabled user interaction

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;

CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *) graph.newPlotSpace;
newPlotSpace.allowsUserInteraction = YES;

I have also done this

self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds]; 

self.hostView.allowPinchScaling = YES;
[self.view addSubview:self.hostView];

But the second plot does not zoom. I am unable to understand why.

Edit

Here is my full code

enter image description here

Was it helpful?

Solution

You're creating two new plot spaces but only adding one to the graph. The one with user interaction enabled in -configureGraph is different from the one created in -configurePlots and added to the graph.

The -newPlotSpace method creates a new plot space object for you. In -configureGraph, give it an identifier and add it to the graph (move those lines from -configurePlots). When you need to refer to it later (e.g., in -configurePlots), do this:

CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *)[graph plotSpaceWithIdentifier:@"Fd Plot Space"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top