Search code examples
iosswiftios-charts

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?


Solution

  • 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. :-)