如何使用iOS图表设置X轴标签
我最近开始使用ios图表库,但是在查找有关如何使用swift3更新操作x轴的信息时遇到了麻烦.
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.
我想做的是用时间值标记x轴,例如2:03:00、2:03:01、2:03:02等.在我在线上找到的教程中,这似乎非常容易;其中许多使用一年中的月份作为x轴标签.
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.
但是,在swift3更新中,图表现在使用x和y值初始化值,而且我不确定如何在此版本的库中使用标签.有谁知道如何使用swift3在图表中创建标签?
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?
Swift 3+中X轴字符串标签的正确解决方案
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
barChartView.xAxis.granularity = 1