Get Color for Pie Chart Segment

5 posts, 1 answers
  1. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 28 Sep 2015 Link to this post

    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. 
  2. Answer
    Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 02 Oct 2015 Link to this post

    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
  3. DevCraft banner
  4. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 02 Oct 2015 in reply to Sophi Link to this post

    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. 
  5. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 02 Oct 2015 in reply to Sophi Link to this post

    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. 
  6. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 05 Oct 2015 Link to this post

    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
Back to Top
DevCraft banner