Я делал это раньше, и это сработало!Вы можете использовать NSArray
для графиков, создать некоторые данные графиков и добавить их как объекты в NSDictionary
.Более подробно вы можете увидеть этот пример:
NSDictionary *firstLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"firstLine", PLOT_IDENTIFIER, firstLineData, PLOT_DATA, nil];
NSDictionary *secondLineDic = [NSDictionary dictionaryWithObjectsAndKeys:@"secondLine", PLOT_IDENTIFIER, secondLineData, PLOT_DATA, nil];
NSArray *arrayData = [NSArray arrayWithObjects:firstLineDic, secondLineDic, nil];
scatterPlot = [[ScatterPlot alloc] initWithHostingView:plotView data:arrayData];
[scatterPlot initialisePlot];
Теперь в ScatterPlot
классе напишите эти функции:
-(id)initWithHostingView:(CPTGraphHostingView *)_hostingView data:(NSArray *)_data{
self = [super init];
if ( self != nil ) {
self.hostingView = _hostingView;
data = [[NSArray alloc] initWithArray:_data];
self.graph = nil;
}
return self;
}
-(void)initialisePlot
{
...
for (NSDictionary *dic in data) {
CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
plot.dataSource = self;
plot.identifier = [dic objectForKey:PLOT_IDENTIFIER];
plot.dataLineStyle = [lineStyles objectAtIndex:[dic objectForKey:PLOT_COLOR]];
plot.plotSymbol = plotSymbol;
[self.graph addPlot:plot];
}
...
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
for (NSDictionary *dic in data) {
NSString *identity = [dic objectForKey:PLOT_IDENTIFIER];
if([plot.identifier isEqual:identity]){
NSArray *arr = [dic objectForKey:PLOT_DATA];
return [arr count];
}
}
return 0;
}