Hi there! I'm facing this issue to format the value printed inside of my Pie Chart and i wasn't able to figure out how to do this:
My chart is printing the values with decimal points but i need Int instead.
I call the func setChart(dataPoints: [String], values: [Double])
with an converted Int to Double for de values. It works, but a want to get rid of the decimal chars. I now it must be done with a formater, so i found this in the PieChartViewController.m demo.
NSNumberFormatter *pFormatter = [[NSNumberFormatter alloc] init];
pFormatter.numberStyle = NSNumberFormatterPercentStyle;
pFormatter.maximumFractionDigits = 1;
pFormatter.multiplier = @1.f;
pFormatter.percentSymbol = @" %";
[data setValueFormatter:[[ChartDefaultValueFormatter alloc] initWithFormatter:pFormatter]];
This is all i needed so i tried to replicate this converting to swift 3 since it's Obj-C and changing the numberStyle. Everything doing fine til i reach the last line. The newest dataset takes an IVALUEFORMATTER instead of NSNUMBER. How do i set this Chart's IVALUEFORMATTER since its don't have the properties like NSNUMBER?
I'll be glad for any help!
Not sure how it is in Objective-C, but in Swift you can use axis.valueFormatter = DefaultAxisValueFormatter(formatter: myNumberFormatter)
Thanks patreu22.... I tried this:
let pFormatter = NumberFormatter()
pFormatter.numberStyle = .none
MyChart.xAxis.valueFormatter = DefaultAxisValueFormatter(formatter: pFormatter)
But.... fatal error: PieChart has no XAxis:
By the way...i'm using swift 3... the demo code is in obj-c(i don't know why its not updated).
Sorry, I overread the things about Objective-C haha.
Does pieChart.data?.setValueFormatter(DefaultValueFormatter(formatter: pFormatter))
work for you?
Perfect, patreu22.
Thanks so much!
Most helpful comment
Sorry, I overread the things about Objective-C haha.
Does
pieChart.data?.setValueFormatter(DefaultValueFormatter(formatter: pFormatter))
work for you?