柱状图的x轴文字设置方法变成使用代理
具体github.com/danielgindi/Charts/issues/1496
给出大致代码
Class ChartViewController : UIViewController, IAxisValueFormatter //step1, 遵守代理 {
var xVals = [String]() // step2, Declare a global variable array for time
override func viewDidLoad() {
super.viewDidLoad()
setupChartStyle() // step 3
}
func setupChartStyle() {
combinedChartView.chartDescription?.text = ""
combinedChartView.noDataText = "加载中..."
combinedChartView...
combinedChartView.xAxis.valueFormatter = self // Important statement, don't forgot this st.
}
func setChartData() { // set ChartData DataSource step 4 这一步配置x轴lable, 我没用
for i in 0..
xVals.append("Time string formatted") // In this step, you can format time strings.
}
}
// return xVals value func
stringForValue(_ value: Double, axis: AxisBase?) -> String {//实现代理方法xVals总的数组
return xVals[Int(value) % xVals.count]
}// OR
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return xVals[Int(value)]
}
}
charts使用分组柱状图
网友评论