我想知道如何通过在 iPhone 项目上使用核心图来更改部分散点图的线条颜色。例如,如果 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];
}
}