我需要在不同時間在同一個圖中繪製多個圖。請看下圖:如何在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