Core-Plot PieChart切片颜色

ran*_*dom 10 iphone core-plot

我在我的一个iPhone项目中使用核心情节.是否可以更改饼图中所选切片的颜色(使用CPPieChartDataSource,CPPieChartDelegate)?

Eri*_*och 18

在饼图数据源中实现以下方法:

-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index; 
Run Code Online (Sandbox Code Playgroud)

CPFill可以是颜色,图像或渐变.


cha*_*dan 5

在你的.h文件中

#import "CPTPieChart.h"
@interface YourViewController : UIViewController<CPTPlotDataSource,CPTPieChartDataSource, CPTPieChartDelegate>
{   
}
Run Code Online (Sandbox Code Playgroud)

在.m文件中

-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
{    
    CPTFill *areaGradientFill ;

    if (index==0)
        return areaGradientFill= [CPTFill fillWithColor:[CPTColor orangeColor]];
    else if (index==1)
        return areaGradientFill= [CPTFill fillWithColor:[CPTColor greenColor]];
    else if (index==2)
        return areaGradientFill= [CPTFill fillWithColor:[CPTColor yellowColor]];

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

它会改变PieChart Slice的颜色.谢谢