绘制第二个地块空间

时间:2014-06-05 17:38:15

标签: objective-c core-plot

我有两个情节空间

//First Plot Space
self.plotSpace1 =(CPTXYPlotSpace *) self.hostingView.hostedGraph.defaultPlotSpace;

[self.plotSpace1 setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(100)]];

[self.plotSpace1 setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(([startNumber floatValue]/1000000) ) length:CPTDecimalFromFloat( ([endLength floatValue]/1000000))]];

//Second Plot Space
self.plotSpace2 =(CPTXYPlotSpace *) [self.hostingView.hostedGraph newPlotSpace];
[self.plotSpace2 setGraph:self.hostingView.hostedGraph];
[self.plotSpace2 setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(1)]];
[self.plotSpace2 setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( ([startNumber floatValue]/1000000) ) length:CPTDecimalFromFloat( ([endLength floatValue]/1000000) )]];
[self.plotSpace2 setIdentifier:@"PLOT2"];

[self.plotSpace2 setAllowsUserInteraction:YES];

[self.hostingView.hostedGraph addPlotSpace:self.plotSpace2];

当我将绘图添加到第二个绘图空间时,如此

CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
plot.title = plotTitle;
plot.dataSource = self;
[plot setPlotSpace:self.plotSpace2];
[self.hostingView.hostedGraph addPlot:plot toPlotSpace:self.plotSpace2];

我像这样添加第二个y轴 - 显示第二个y轴

CPTXYAxis *rightY = [(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero];
rightY.axisConstraints = [CPTConstraints constraintWithUpperOffset:0.0];
rightY.coordinate = CPTCoordinateY;
rightY.plotSpace = self.plotSpace2;


//Labeling and intervals
rightY.labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
rightY.majorIntervalLength = CPTDecimalFromCGFloat(0.1f);
rightY.minorTicksPerInterval = 5;

rightY.orthogonalCoordinateDecimal = CPTDecimalFromDouble(self.plotSpace2.xRange.locationDouble + self.plotSpace2.xRange.lengthDouble);
rightY.title = nil;


//Format and position
rightY.titleTextStyle = axisTitleStyle;
rightY.titleOffset = 20.0f;
rightY.axisLineStyle = axisLineStyle;
rightY.labelTextStyle = axisTextStyle;
rightY.labelOffset = 2.0f;
rightY.majorTickLineStyle = axisLineStyle;
rightY.majorTickLength = 4.0f;
rightY.minorTickLength = 2.0f;
rightY.tickDirection = CPTSignPositive;

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

未绘制线条。但是,如果我将它添加到plotSpace1(默认绘图空间),则会绘制它。

我已经坚持了一段时间了。我疯狂地搜索和搜索了一个答案。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

第一个绘图空间的yRange从0到100,而第二个yRange在0到1之间。绘图数据可能在可见绘图范围之外。

您应该只将图表添加到图表中一次:

CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
plot.title = plotTitle;
plot.dataSource = self;
[self.hostingView.hostedGraph addPlot:plot toPlotSpace:self.plotSpace2];