我想知道如何在iPhone项目中使用Core Plot更改散点图的部分线条颜色。例如,如果Y轴当前值>上一个值,则将线条颜色更改为红色,否则线条颜色保持为绿色。以下是我的代码,但我发现颜色没有更改部分绘图,而是更改了整个绘图。:( 如果有人能给出建议,我将不胜感激。
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
CPTScatterPlot *myPlot = (CPTScatterPlot *)plot;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineWidth = 3.f;
lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.0f], [NSNumber numberWithFloat:5.0f], nil];
NSLog(@"index: %d",index);
if(index < 7 && index > 0 && fieldEnum == CPTScatterPlotFieldY){
if ([[dataForPlot objectAtIndex:index] floatValue] > [[dataForPlot objectAtIndex:index-1] floatValue]) {
//lineStyle.lineColor = [CPTColor redColor];
NSLog(@"%f > %f",[[dataForPlot objectAtIndex:index] floatValue],[[dataForPlot objectAtIndex:index-1] floatValue]);
lineStyle.lineColor = [CPTColor redColor];
myPlot.dataLineStyle = lineStyle;
}else {
lineStyle.lineColor = [CPTColor greenColor];
myPlot.dataLineStyle = lineStyle;
}
}
if(fieldEnum == CPTScatterPlotFieldX){
return [NSNumber numberWithInt:index];
}else if(fieldEnum == CPTScatterPlotFieldY){
return [dataForPlot objectAtIndex:index];
}
}