【发布时间】:2012-03-18 10:54:49
【问题描述】:
我需要在不同时间在同一张图中绘制多个图。请看下图:
除了地块的数量会动态变化。有时我只需要蓝色和橙色数据集,有时是全部四个,有时只需要 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];
}
【问题讨论】:
标签: core-plot