How to show the percentage of a pie chart?

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    5 posts
    Member since:
    Aug 2013

    Posted 20 Oct 2015 Link to this post

    Hello,

    I am using the latest version of Telerik iOS frame work. How can I show the percentage of a pie chart? Here is my code.

     

    - (void)viewDidLoad {
        [super viewDidLoad];
        TKChart *chart = [[TKChart alloc] initWithFrame:CGRectInset(self.view.bounds, 15, 15)];
        chart.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self.view addSubview:chart];


        NSMutableArray *pointsWithValueAndName = [[NSMutableArray alloc] init];
        [pointsWithValueAndName addObject:[[TKChartDataPoint alloc] initWithName:@"Google" value:@20]];
        [pointsWithValueAndName addObject:[[TKChartDataPoint alloc] initWithName:@"Apple" value:@30]];
        [pointsWithValueAndName addObject:[[TKChartDataPoint alloc] initWithName:@"Microsoft" value:@20]];
        [pointsWithValueAndName addObject:[[TKChartDataPoint alloc] initWithName:@"IBM" value:@20]];
        [pointsWithValueAndName addObject:[[TKChartDataPoint alloc] initWithName:@"Oracle" value:@10]];

        TKChartPieSeries *series = [[TKChartPieSeries alloc] initWithItems:pointsWithValueAndName];
        [chart addSeries:series];
        chart.legend.hidden = NO;
        chart.legend.style.position = TKChartLegendPositionRight;
        series.labelDisplayMode = TKChartPieSeriesLabelDisplayModeInside;

    //    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    //    [numberFormatter setNumberStyle:NSNumberFormatterSpellOutStyle];
    //    series.style.pointLabelStyle.formatter = numberFormatter;
    series.style.pointLabelStyle.stringFormat = @"%.0f %%";
    }

     

     

    With the NSNumber formatter nothing is showing as well​.

     

     

  2. Miroslava
    Admin
    Miroslava avatar
    19 posts

    Posted 21 Oct 2015 Link to this post

    Hello Andrew, 

    Thank you for contacting us.

    You can show percentage labels in pie chart by setting displayPercentage and textHidden properties of series style. Consider the following code:
    series.displayPercentage = YES;
    series.style.pointLabelStyle.textHidden = NO;

    Do not hesitate to contact us in case you need further assistance. 

    Regards,
    Miroslava
    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
Back to Top