Dinesh
Dinesh

Reputation: 2204

CorePlot : 2 Y axes using different plot spaces - formatting issue

I have two y-axes with different scales. So I added another plot space. I used the same xRange for the second plot space, but use a different yRange, e.g.,

CPTXYPlotSpace *plotSpace2 = [[CPTXYPlotSpace alloc] init];
plotSpace2.xRange = plotSpace.xRange;
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin)
                                             length:CPTDecimalFromFloat(ymax2 - ymin)];
[graph addPlotSpace:plotSpace2];
y2.plotSpace = plotSpace2;

I have also added the y2 axis to the axisSet after configuring it.

graph.axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil];

To make the x axis intersect the left y axis, I have used the following.

axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-4");
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-0.5");

How can I do the same with the y2 axis? I would like the x axis to intersect the y2 axis at the point -1.

Upvotes: 1

Views: 281

Answers (1)

Jeff Loughlin
Jeff Loughlin

Reputation: 4174

The orthogonal coordinate for the X axis has to be relative to one Y axis or the other, not both. If you have two plot spaces with different yRanges, I think you can achieve what you want by setting the orthogonal coordinate for the X axis relative to your left Y axis, then adjust the yRange for plotSpace2 so that the X axis intersects Y2 at the desired coordinate.

axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-0.5");

// Adjust yRange as needed to get the axis to intersect where you want it to
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:(CPTDecimalFromFloat(-1.0) length:CPTDecimalFromFloat(ymax2 - ymin2)]; 

Upvotes: 1

Related Questions