我需要在不同时间在同一个图中绘制多个图。请看下图:如何在coreplot中绘制多个图
除了地块数量会动态改变。有时候,我只需要四次,一次只需要蓝色和橙色数据集,而有些时候只需要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];
}
嗨MrMage,感谢您的quichk响应,你能告诉我如何将我分配动态标识和更困难的问题是如何在if循环中比较它们([plot.identifier isEqual:@“mainplot”])。在上面的示例中,“mainplot”是硬编码的。我将如何改变这是动态的。 – Rajashekar 2012-03-18 11:41:12
我相信,如果你仔细想想,你可以自己弄清楚。 – MrMage 2012-03-18 11:49:54
我在给我最好的猜测。 CPTPlot * tempPlot = [self.graph objectatindex:indexpath.row];如果([plot.identifier isEqual:tempPlot.identifier])//我确信self.graph不会采用objectatindex方法。我想知道它可以采取什么方法? – Rajashekar 2012-03-18 13:00:46