Search code examples
iosobjective-ccore-plotpie-chart

How to get color from slice index?


I implemented corePlot in my xcode project. I know there is a way to fill the pie slices color:

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

But is there a way to get what color the index's slice is?

Example:

enter image description here

If I try getting index's 0 color, it would be blue, etc.


Solution

  • Usually you fill out the DataSource function to provide the color, which means you already have the color. For you case, I think you could use this function:

    + (CPTColor *) defaultPieSliceColorForIndex:(NSUInteger) pieSliceIndex

    The doc is here.

    To get the UIColor of CPTColor, simply get the CPTColor's property uiColor. Detailed information is available on Doc.