How can I format the percentage values in the pie chart segments to omit the decimals? e.g i want it to show 20% instead of 20.00%. The values I pass in are always rounded
- Marcus Maringer asked 1 year ago
- last edited 1 year ago
- You must login to post comments
Good morning Marcus,
Pie chart labels can be formatted using a Custom class implementing SCIPieSegmentLabelFormatterBase
take a look at the Pie Chart documentation page here.
Pie Segment Label Formatter
By default, the Pie Segment Label displays a relative percentage
calculated on values of all segments in SCIPieDonutRenderableSeriesBase.segmentsCollection.
This behavior can be controlled and to do so you’ll need to subclass SCIPieSegmentLabelFormatterBase
and provide your custom data in ISCIPieSegmentLabelFormatter formatLabelForPieSegment method.
As an example, let’s create a label that displays a segment absolute
value. Assume, we create a donutSeries and add four segments with
values 40, 10, 20, and 15. Here is the code sample, how to do this:class CustomPieSegmentLabelFormatter: SCIPieSegmentLabelFormatterBase { override func formatLabel(for pieSegment: ISCIPieSegment!) -> String! { return “\(pieSegment.value)” } } // Assume a donutSeries has been created somewhere let donutSeries = SCIDonutRenderableSeries() donutSeries.pieSegmentLabelFormatter = CustomPieSegmentLabelFormatter()
This produces the following output:
Please let me know if this helps
Best regards
Andrew
- Andrew Burnett-Thompson answered 1 year ago
- You must login to post comments
Please login first to submit.