我是Core-Plot的新手,并尝试在两个不同y轴的plotSpaces中绘制两个图。但数据源正在绘制默认plotSpace中的两个图。
我的代码段是这样的:
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xmin) length:CPTDecimalFromFloat(xmax-xmin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin) length:CPTDecimalFromFloat(ymax-ymin)];
// set the axes
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.coordinate = CPTCoordinateX;
CPTXYAxis *y = axisSet.yAxis;
y.coordinate = CPTCoordinateY;
//Adding second y-axis
CPTXYAxis *y2 = (CPTXYAxis *)[[CPTXYAxis alloc] initWithFrame:CGRectZero];
CPTXYPlotSpace *plotSpace2 = [[CPTXYPlotSpace alloc] init];
plotSpace2.xRange = plotSpace.xRange;
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin) length:CPTDecimalFromFloat(ymax2 - ymin)];
[self.graph addPlotSpace:plotSpace2];
y2.plotSpace = plotSpace2;
y2.coordinate = CPTCoordinateY;
self.graph.axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil];
// Create a plot that uses the data source method for red graph
CPTScatterPlot *redPlot = [[CPTScatterPlot alloc] init];
redPlot.identifier = RED_PLOT;
CPTMutableLineStyle *lineStyle = [redPlot.dataLineStyle mutableCopy];
lineStyle.miterLimit = 1.0f;
redPlot.dataLineStyle = redLineStyle;
redPlot.dataSource = self;
[self.graph addPlot: redPlot];
// Create a plot that uses the data source method for green graph
CPTScatterPlot *greenPlot = [[CPTScatterPlot alloc] init];
greenPlot.identifier = GREEN_PLOT;
CPTMutableLineStyle *greenlineStyle = [greenPlot.dataLineStyle mutableCopy];
greenlineStyle.miterLimit = 1.0f;
greenPlot.dataLineStyle = greenLineStyle;
greenPlot.dataSource = self;
[self.graph addPlot: greenPlot];
我有两个数据源(可变阵列)用于设置这些图。无论如何,图表都是绘图,但问题是在默认的图表空间中绘图。新添加的图表空间不包含任何图表。
我也试过了[self.graph addPlot:greenPlot toPlotSpace:plotSpace2];
。绿色情节没有在情节区域绘制。然而,绘制了第二个绘图空间的网格线和轴。
我做错了什么?请指导我。
谢谢, 克里斯