iOS-Charts Float to Integer YAxis
I’m building a chart using iOS-charts
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?
4 Solutions Collect From Internet About “iOS-Charts Float to Integer YAxis”
You just need to adjust the
yAxis.valueFormatter = NSNumberFormatter() yAxis.valueFormatter.minimumFractionDigits = 0
NSNumberFormatter is a very powerful class, you can do much much more with it. 🙂
For Swift 3.0 and Charts 3.0 you need to enable and set granularity for the axis.
barChart.leftAxis.granularityEnabled = true barChart.leftAxis.granularity = 1.0
This worked for me. However, the y-axis labels will round when displaying small numbers, so if you are charting, say 1 or 2, the chart will display 0 twice. (See here: Force BarChart Y axis labels to be integers?)
let numberFormatter = NSNumberFormatter() numberFormatter.generatesDecimalNumbers = false chartDataSet.valueFormatter = numberFormatter // Converting to Int for small numbers rounds weird //barChartView.rightAxis.valueFormatter = numberFormatter //barChartView.leftAxis.valueFormatter = numberFormatter
You can try this one, it worked nicely for me
let formatter = NSNumberFormatter() formatter.numberStyle = .NoStyle formatter.locale = NSLocale(localeIdentifier: "es_CL") BarChartView.leftAxis.valueFormatter = formatter
- “-(id) init” do not fire in ViewController when using storyboard
- The “prefs” URL Scheme not woring in iOS 10 (Beta 1 & 2)
- Cocoa singleton and shared instances
- ionic update-notifier-cordova.json' You don't have access to this file
- How to call an Objective C class method in Swift
- Most performant way to draw text on a curve, and animate it?
- iOS Push notifications not working on for ad hoc distributions with Test Flight
- NSDictionaryOfVariableBindings swift equivalent?
- Disabling back button and put Cancel button in navigation view controller — like contacts iPhone application
- Undefined symbols for architecture armv7: “_OBJC_CLASS_$_GGLContext”, referenced from: objc-class-ref in AppDelegate.o
- Is it possible to access Swift global variables from an objective-c file?
- Truncate UILabel in specific location
- shouldAutorotateToInterfaceOrientation not being called in iOS 6
- How to programmatically increase UITableView cell's height in iPhone?
- How to add one project to another(Xcode)