Here I have added no of co-ordinates to dataForPlot (which is an mutable array).I’m trying to display ONE set of co-ordinates here. so I have returned [dataForPlot count] in numberOfRecordsForPlot method.This is working fine.
but now I have different-different sets of co-ordinates(i.e. 4 to 5 for loops which I have used in viewDidLoad method)
I want to show those 4 to 5 sets/records on plot with different color for each set.
what should I return in numberOfRecordsForPlot method and any change needed in numberForPlot method?How should I achieve that?
I’m new to core plot.
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
NSUInteger i;
for ( i = 0; i < 60; i++ ) {
id x = [NSNumber numberWithFloat:1+i*0.05];
id y = [NSNumber numberWithFloat:1.2*rand()/(float)RAND_MAX + 1.2];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
}
self.dataForPlot = contentArray;
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return [dataForPlot count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = nil;
num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y")];
return num;
}
First, you should read sample code. CPTTestAPP-iPhone. It has two scatter plots. Green one and Blue one.
All sample src code is included in CorePlot package.
If your application is for iOS5 and ARC(Automatic Reference Count), you should download latest full CorePlot package by using Mercurial. Because 0.90 release does not include recent modification for ARC.
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
Above two meshods are CPTPlot’s data source.
Even you have many scatter plot, each your scatter plot can have identifier. So data source can dtermine who is real client.