Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS-Charts Float to Integer YAxis

I'm building a chart using iOS-charts IOS CHART

I'm trying to convert the floats into int, but iOS-charts only allows for Floats in the data entry:

      let result = ChartDataEntry(value: Float(month), xIndex: i)

Does anyone know the method for making sure only ints are used?

like image 260
HannahCarney Avatar asked Jul 09 '15 13:07

HannahCarney


2 Answers

For Swift 3.0 and Charts 3.0 you need to enable and set granularity for the axis.

Example:

barChart.leftAxis.granularityEnabled = true
barChart.leftAxis.granularity = 1.0
like image 79
Seref Bulbul Avatar answered Nov 05 '22 19:11

Seref Bulbul


You just need to adjust the NSNumberFormatter...

Example:

yAxis.valueFormatter = NSNumberFormatter()
yAxis.valueFormatter.minimumFractionDigits = 0

NSNumberFormatter is a very powerful class, you can do much much more with it. :-)

like image 32
daniel.gindi Avatar answered Nov 05 '22 20:11

daniel.gindi