From 8d73eaf636aa5eb00454c0ceb397963024a82a72 Mon Sep 17 00:00:00 2001 From: chisj Date: Mon, 18 Apr 2016 13:59:31 +0800 Subject: [PATCH] PNPieChart to support Percentage Value Decimal Places --- PNChart/PNPieChart.h | 3 +++ PNChart/PNPieChart.m | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PNChart/PNPieChart.h b/PNChart/PNPieChart.h index 204afb53..a280a9fe 100644 --- a/PNChart/PNPieChart.h +++ b/PNChart/PNPieChart.h @@ -38,6 +38,9 @@ /** Show absolute values not relative i.e. percentages */ @property (nonatomic) BOOL showAbsoluteValues; +/** Show Percentage values decimal places i.e. 0 */ +@property (nonatomic) int showPercentageValueDecimalPlaces; + /** Hide percentage labels less than cutoff value */ @property (nonatomic, assign) CGFloat labelPercentageCutoff; diff --git a/PNChart/PNPieChart.m b/PNChart/PNPieChart.m index 07154677..a463ccff 100644 --- a/PNChart/PNPieChart.m +++ b/PNChart/PNPieChart.m @@ -69,6 +69,7 @@ - (void)baseInit{ _shouldHighlightSectorOnTouch = YES; _enableMultipleSelection = NO; _hideValues = NO; + _showPercentageValueDecimalPlaces = 0; [super setupDefaultValues]; [self loadDefault]; @@ -155,7 +156,7 @@ - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{ if (self.showAbsoluteValues) { titleValue = [NSString stringWithFormat:@"%.0f",currentDataItem.value]; }else{ - titleValue = [NSString stringWithFormat:@"%.0f%%",[self ratioForItemAtIndex:index] * 100]; + titleValue = [NSString stringWithFormat:@"%.*f%%",self.showPercentageValueDecimalPlaces, [self ratioForItemAtIndex:index] * 100]; } if (self.hideValues)