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

How to show the percentage of a pie chart?

1 Answer 736 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.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Oct 2015, 03:04 AM

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​.

 

 

1 Answer, 1 is accepted

Sort by
0
Miroslava
Telerik team
answered on 21 Oct 2015, 10:00 AM
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
Tags
Chart
Asked by
Andrew
Top achievements
Rank 1
Answers by
Miroslava
Telerik team
Share this question
or