Search code examples
ioslocalizationnsnumberformattershinobi

How to localize the axis number labels for the Shinobi iOS SDK?


The numbers for the axis labels are not getting localized as expected. When I change the region setting to something like Netherlands the numbers still show with US region formatting. The period is used as a decimal separator and a comma is used to separate the thousands. How do I force Shinobi to use a NSNumberFormatter for the tick mark labels?


Solution

  • SChartAxis objects have a property called labelFormatter, which is of type SChartTickLabelFormatter. This object is used to represent formatters for axes of both number and datetime types. You can set the properties on the formatter property of the labelFormatter to configure the labels appropriately.

    The numberFormatter and dateFormatter properties allow access to pre-casted versions of the formatter property:

    For example, on a SChartNumberAxis you could use the following line to use the textual form of the numbers (e.g. 'five' instead of '5'):

    [_chart.xAxis.labelFormatter.numberFormatter
                                     setNumberStyle:NSNumberFormatterSpellOutStyle];
    

    If you want to set the format on a SChartDateAxis instead of an SChartNumberAxis then use labelFormatter.dateFormatter to return a NSDateFormatter which you can configure how you wish.