Charts: valueFormatter API changes in Swift 3

Created on 24 Sep 2016  路  2Comments  路  Source: danielgindi/Charts

I could not figure out from example how the new Chart 3.0 API works for valueFormatter. Below is previous version of snippet. Please advise.

let formatter = NumberFormatter()
formatter.numberStyle = .none
lineChartAltitude.leftAxis.valueFormatter = formatter

Most helpful comment

For other benefit. Here are the examples.
@danielgindi Hope below example is right and I can see working now. Please advise.

Line Chart

let format = NumberFormatter()
format.numberStyle = .none   
let formatter = DefaultValueFormatter(formatter: format)
lineChartSpeed.leftAxis.valueFormatter = (formatter as? IAxisValueFormatter)

Pie Chart

let format = NumberFormatter()
format.numberStyle = .none
let formatter = DefaultValueFormatter(formatter: format)
pieChartData.setValueFormatter(formatter)

All 2 comments

The new API does not inherit from the Cocoa's formatters. It passes more information about the value to be formatted, like the X value.
_But_ the formatters can take a number formatter - https://github.com/danielgindi/Charts/blob/master/Source/Charts/Formatters/DefaultAxisValueFormatter.swift#L56, https://github.com/danielgindi/Charts/blob/master/Source/Charts/Formatters/DefaultValueFormatter.swift#L56

You can read the migration notes - it tells exactly how to deal with it if you're not interested in the new formatter api :-)

For other benefit. Here are the examples.
@danielgindi Hope below example is right and I can see working now. Please advise.

Line Chart

let format = NumberFormatter()
format.numberStyle = .none   
let formatter = DefaultValueFormatter(formatter: format)
lineChartSpeed.leftAxis.valueFormatter = (formatter as? IAxisValueFormatter)

Pie Chart

let format = NumberFormatter()
format.numberStyle = .none
let formatter = DefaultValueFormatter(formatter: format)
pieChartData.setValueFormatter(formatter)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kwstasna picture kwstasna  路  3Comments

heumn picture heumn  路  3Comments

coop44483 picture coop44483  路  3Comments

JW00332 picture JW00332  路  4Comments

Shunshine07 picture Shunshine07  路  3Comments