Reputation: 673
How to draw multiple lines in coreplot i can plot one data like this
// Create a green plot area
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = @"Green Plot";
CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 2.f;
lineStyle.lineColor = [CPTColor greenColor];
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:8.0f], nil];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
// Put an area gradient under the plot above
CPTColor *areaColor = [CPTColor colorWithComponentRed:0.0 green:1.0 blue:0.0 alpha:1];
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
//areaGradient.angle = -90.0f;
CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill = areaGradientFill;
// dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0.05");// green line shade below point
// Animate in the new plot, as an example
dataSourceLinePlot.opacity = 0.2f;
dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDecimal;
[graph1 addPlot:dataSourceLinePlot];
but how to add 2 graph data ,since i want to compare week data
i know i have to tweak this , but this code takes eiher of the value but not both'
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = nil;
{
if ( index % 8 ) {
num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y")];
// Green plot gets shifted above the blue
if ( [(NSString *)plot.identifier isEqualToString:@"Green Plot"] ) {
if ( fieldEnum == CPTScatterPlotFieldY ) {
num = (NSDecimalNumber *)[NSDecimalNumber numberWithDouble:[num doubleValue] + 1.0];
}
}
else if ( [(NSString *)plot.identifier isEqualToString:@"Green Plot1"] ) {
num = [[dataForPlot1 objectAtIndex:index] valueForKey:(fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y")];
if ( fieldEnum == CPTScatterPlotFieldY ) {
num = (NSDecimalNumber *)[NSDecimalNumber numberWithDouble:[num doubleValue] + 1.0];
}
}
}
else {
num = [NSDecimalNumber notANumber];
}
}
return num;
}
i wan to show both Green plot and Green plot 1 data
Upvotes: 2
Views: 2161
Reputation: 673
its working now , but how to change the color
CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease]; dataSourceLinePlot.identifier = @"Green Plot";
CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 12.f;
lineStyle.lineColor = [CPTColor redColor];
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:8.0f], nil];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
// Put an area gradient under the plot above
CPTColor *areaColor = [CPTColor colorWithComponentRed:0.0 green:1.0 blue:0.0 alpha:1];
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
// areaGradient.angle = -90.0f; CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient]; dataSourceLinePlot.areaFill = areaGradientFill; // dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0.05");// green line shade below point
// Animate in the new plot, as an example
dataSourceLinePlot.opacity = 0.2f;
dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDecimal;
[graph1 addPlot:dataSourceLinePlot];
CPTScatterPlot *dataSourceLinePlot1 = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot1.identifier = @"Green Plot1";
// CPTMutableLineStyle *lineStyle1 = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
CPTMutableLineStyle *lineStyle1= [CPTMutableLineStyle lineStyle];
lineStyle1.lineWidth = 12.f;
lineStyle1.lineColor = [CPTColor greenColor];
lineStyle1.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:18.0f], nil];
dataSourceLinePlot1.dataLineStyle = lineStyle;
dataSourceLinePlot1.dataSource = self;
// Put an area gradient under the plot above
CPTColor *areaColor1 = [CPTColor colorWithComponentRed:0.0 green:1.0 blue:0.0 alpha:1];
CPTGradient *areaGradient1 = [CPTGradient gradientWithBeginningColor:areaColor1 endingColor:[CPTColor clearColor]];
//areaGradient.angle = -90.0f;
CPTFill *areaGradientFill1 = [CPTFill fillWithGradient:areaGradient1];
dataSourceLinePlot1.areaFill = areaGradientFill1;
// dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0.05");// green line shade below point
// Animate in the new plot, as an example
dataSourceLinePlot1.opacity = 0.2f;
dataSourceLinePlot1.cachePrecision = CPTPlotCachePrecisionDecimal;
[graph1 addPlot:dataSourceLinePlot1 ];//toPlotSpace:plotSpace
Upvotes: 2