如何使用Core Plot更改散点图部分线条颜色?

3

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

嗨,我也有同样的需求...你找到解决方案了吗? 谢谢... - Pavan Kumar
嘿,老兄,你找到解决方案了吗?请告诉我。 - SRI
1个回答

1

目前不支持此功能。您必须为每个颜色/线条样式使用不同的图表。


@Eric Skroch 我已经更新了这个问题的答案。如果需要请进行更正。谢谢。 - Vijay-Apple-Dev.blogspot.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接