水平条形图:如何添加X-Bar轴标签

时间:2017-01-21 09:15:19

标签: ios swift charts

我在这里使用Charts Library 对于水平条形图, 我已将代码设置如下

.zshrc

X轴数据为蓝色。

我想在X轴上设置String。我怎么能这样做?

任何帮助都是赞赏的

enter image description here

否则, 为横条建议任何其他图表库,包括条形值动画

1 个答案:

答案 0 :(得分:1)

您可以在自己的课程中实施IAxisValueFormatter

为此你只需要实现这个方法:

func stringForValue(_ value: Double, axis: AxisBase?) -> String

示例:

或您关注RayWenderlich Tutorial "Using Realm and Charts with Swift 3 in iOS 10"

您必须设置一些代理人,但这是自定义格式化程序的关键代码段:

// MARK: axisFormatDelegate
extension ViewController: IAxisValueFormatter {

  func stringForValue(_ value: Double, axis: AxisBase?) -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = “HH:mm.ss”
    return dateFormatter.string(from: Date(timeIntervalSince1970: value))
  }
}