Format numbers inside graph axes


#1

Hi,

I would like to format numbers on y-axes of the graph.
Instad of a 1.000.000.000 €, I would like to format it like this : 1 B€

Explanation:

I can achieve to display 1.000,00 € by applying the formatter to y-axes, like this :

let numberFormatter = NumberFormatter()
numberFormatter.positiveFormat = "#,###.00 €"
self.yAxis?.labelFormatter?.formatter = numberFormatter

There is no good way of dividing the number in format to display B€, so I create my own class NumberFormatterWithMask that override method string(from: number), that handle this.

If I use this new Formatter any where else, it is working perfect, but if I do this for y-axis it doesn’t

let numberFormatter = NumberFormatterWithMask()
numberFormatter.positiveFormat = "#,###.00 B€"
self.yAxis?.labelFormatter?.formatter = numberFormatter

Which method of the formatter is used for displaying the numbers?


#2

Hi Marko,

The labelFormatter property of the axis is an instance of SChartTickLabelFormatter. We recommend subclassing SChartTickLabelFormatter and providing your own implementation of the stringForObjectValue:onAxis: method.

I hope that helps.

Kind regards,

Alison