【问题标题】:How do I change the line color for a part of scatterPlot by using core plot?如何使用核心图更改散点图一部分的线条颜色?
【发布时间】:2012-04-10 06:19:53
【问题描述】:

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

【问题讨论】:

  • 嗨..我也有同样的要求...你有解决方案吗???谢谢你...
  • 嘿伙计,你找到解决方案了吗?请告诉我

标签: iphone objective-c core-plot scatter-plot


【解决方案1】:

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

【讨论】:

  • @Eric Skroch 我已经更新了这个问题的答案。如果需要,请更正。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 2022-12-12
  • 1970-01-01
  • 2014-09-24
  • 1970-01-01
相关资源
最近更新 更多