Pie chart using set colors


#1

(IOS - question)

I want to create a pie chart with specific colors linked to specific items.  I have looked through the docs and I found stuff on how to do it using Andriod, but it doesn’t seem to correlate to anything I am doing.  For example I have 4 things :

Cars - Red, Trucks - Blue, Bike - Green, and Plane - Yellow. 

I would like to be able to set the colors as outlined, but I can’t seem to figure out what I need to set to get that to work.  I did find a reference to “setFlavourColor” in another post, but I can’t seem to find that in the docs.

Does anyone have an example or can you please help point me in the right direction?

Thanks.


#2

I figured out how to define the colors.  For the sake of an example, and hopefully it’ll save someone a bit of time.  You define it in the datasource in the section:

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index;

Here is an example of flavorcorlors:

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index {
    SChartPieSeries* pieSeries = [[SChartPieSeries alloc] init];
    pieSeries.selectedStyle.protrusion = 10.0f;
    pieSeries.selectionAnimation.duration = @0.4;
    pieSeries.selectedPosition = @0.0;
    pieSeries.style.showFlavour = YES;
    // colorSets is a NSMutableArray of UIColor
    pieSeries.style.flavourColors = [colorSets mutableCopy];
    
    return pieSeries;
}

Now there are a couple of things you will want to keep in mind.  You need to make sure your data is sorted, or you have some other “management key”.  If you just let the chart handle it you will end up with your colors being assigned to the wrong values. 

Hope this helps save someone else some time.


#3

Hello Gymlete.

I am glad that you were able to find answers to your query yourself. I would like to thank you for posting your solution to this forum - I am sure it will help others with a similar query. 

If you have any further questions please do get back in touch.

Kind regards,

Kai.