How to set x-axis labels with ios charts

matt picture matt · Oct 29, 2016 · Viewed 24.5k times · Source

I've recently started using the ios charts library and am having trouble finding information on how to manipulate the x-axis with the swift3 update.

What I want to do is label the x-axis with time values, e.g. 2:03:00, 2:03:01, 2:03:02, etc. In the tutorials I find online, this seems to be very easy; many of them use months of the year as the x-axis label.

However, in the swift3 update, charts now initializes values with x and y values, and I am not sure how to use labels in this version of the library. Does anyone know how to create labels in charts with swift3?

Answer

Shrestha Ashesh picture Shrestha Ashesh · Apr 12, 2017

Proper Solution for X-Axis String labels in Swift 3+

let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
    barChartView.xAxis.granularity = 1