I did it before and it worked! You can use NSArray for plots and create some graph data and add them as objects in an NSDictionary . in more detail you can see this example:
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];
Now in the ScatterPlot class write the following functions:
-(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; }
source share