iPhone:如何在Core Plot中更改负值的渐变颜色?

Par*_*att 7 iphone cocoa-touch objective-c core-plot ios4

如何在iPhone的Core-Plot中的渐变散点图中更改负值的区域渐变颜色?

我想要渐变颜色如下:

  • 正值为绿色

  • 负值为红色.

我该怎么办?

Shi*_*iny 3

只需实现CPBarPlotDataSource的以下方法即可:

- (CPFill *)barFillForBarPlot:(CPBarPlot *)barPlot recordIndex:(NSUInteger)index
{
    if (barPlot.identifier == @"profit") {
        id item = [self.profits objectAtIndex:index];
        double profit = [[item objectForKey:@"profit"] doubleValue];

        if (profit < 0.0) {
            return [CPFill fillWithGradient:[CPGradient gradientWithBeginningColor:[CPColor redColor] endingColor:[CPColor blackColor]]];
        }
    }

    return nil;
}
Run Code Online (Sandbox Code Playgroud)

希望能有所帮助:)