2012-04-10 55 views
2

我想知道如何通过在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]; 
} 
} 
+0

嗨..我也有同样的要求...有你有解决方案吗??? 谢谢你... – 2012-04-11 09:02:12

+0

嘿老兄你有没有得到解决方案?请让我知道 – SRI 2014-06-30 13:12:50

回答

1

这是不支持现在。你必须使用一个不同的情节为您希望每种颜色/线型

+0

感谢您的评论:) – chao 2012-04-13 03:01:13

+0

是否有可能ri现在呢? – 2015-07-28 14:28:40

+0

@Eric Skroch我已经更新了这个问题的答案。请纠正它,如果需要。谢谢。 – 2015-10-08 06:45:43