This is a migrated thread and some comments may be shown as answers.

Get Color for Pie Chart Segment

4 Answers 40 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sal
Top achievements
Rank 1
Sal asked on 28 Sep 2015, 08:46 PM
Is there a way to get the color used for each segment of a pie chart? I wanted to use a TableView for the index (because I needed a more in-depth legend and some other items) but I also wanted to make sure that each cell had the same color as the segment from the Pie Chart just not sure if there is a way to get the color for each segment. I know I can pass my own colors to the Pie Chart and use them for the Table but I wanted to use the built in colors for the chart as well. 

4 Answers, 1 is accepted

Sort by
0
Accepted
Sophi
Telerik team
answered on 02 Oct 2015, 07:32 AM
Hello Sal,

You can get the current color configuration of your pie chart through the style property of your series. 
Please, consider the following code.
TKChartPalette *palette = series.style.palette;
NSMutableArray *colorArray = [NSMutableArray new];
for (int i = 0; i < palette.itemsCount; i++) {
    TKChartPaletteItem *item = [palette paletteItemAtIndex:i];
    [colorArray addObject:item.fill];
}

Now in the colorArray you have all fills (instances of TKSolidFill by default) used for the drawing of the current series.

If you have any other questions, do not hesitate to contact us.

Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Sal
Top achievements
Rank 1
answered on 02 Oct 2015, 04:10 PM
Thanks, that's what I needed but now is there a way to get the UIColor or CGColor from a TKFill? I would need one of those to update the color of a UIView. Thanks. 
0
Sal
Top achievements
Rank 1
answered on 02 Oct 2015, 04:14 PM
Actually I was able to get the UIColor from the TKStroke instead of the TKFill, not sure if there is a way to get the Fill color as well but since the TKStroke has it I just used it from there for now. Thanks. 
0
Sophi
Telerik team
answered on 05 Oct 2015, 08:28 AM
Hi Sal,
Since all the default colors from the pie chart are represented as TKSolidFill instances. You can use the color property of TKSolidFill to access the used UIColor.
UIColor *usedColor = [fill color];
Hope this will get the job done.

Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Sal
Top achievements
Rank 1
Answers by
Sophi
Telerik team
Sal
Top achievements
Rank 1
Share this question
or