我想知道如何通过在iPhone项目上使用核心图来更改散点图一部分的线条颜色。 例如如果Y轴的当前值>之前的值,则线条颜色变为红色,否则线条颜色保持为绿色。下面是我的代码,但是我发现颜色对于一部分情节不会改变,即对整个情节的改变。 :( 感激,如果任何人都可以给一些建议。如何使用核心图更改scatterPlot的一部分线条颜色?
-(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];
}
}
嗨..我也有同样的要求...有你有解决方案吗??? 谢谢你... – 2012-04-11 09:02:12
嘿老兄你有没有得到解决方案?请让我知道 – SRI 2014-06-30 13:12:50