如何使用iOS图表设置X轴标签 [英] How to set x-axis labels with ios charts

查看:150
本文介绍了如何使用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

这篇关于如何使用iOS图表设置X轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆