我需要在同一张图中以不同时机绘制多个图表。请看下面的图片:
不同的是,图表数量会动态变化。有时我只需要蓝色和橙色数据集,有时需要全部四个,有时只需要3个。我已经可以处理一个条形图。
CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
plot.dataSource = self;
plot.identifier = @"mainplot";
plot.dataLineStyle = lineStyle;
plot.plotSymbol = plotSymbol;
[self.graph addPlot:plot];
在我的情况下,我可以将它们放在一个for循环中,并在每次迭代中执行
[self.graph addplot:plot]
。但是,如何管理数据源?如果数据集的数量动态变化,如何管理以下代码?-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
if ( [plot.identifier isEqual:@"mainplot"] )
{
NSValue *value = [self.graphData objectAtIndex:index];
CGPoint point = [value CGPointValue];
// FieldEnum determines if we return an X or Y value.
if ( fieldEnum == CPTScatterPlotFieldX )
{
return [NSNumber numberWithFloat:point.x];
}
else // Y-Axis
{
return [NSNumber numberWithFloat:point.y];
}
}
return [NSNumber numberWithFloat:0];
}
NSMutableArray
替代NSArray
来处理PLOT_DATA
! - Hamed Rajabi Varamini