通过使用以下代码,我可以毫无问题地绘制图表。但是我需要显示所有12个值而不是6个值。在图表区域中双击后,它会显示完整的12个值。如何也可以为默认视图设置相同?
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
使用的xAxisValueFormatter是
extension ReportChart: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
if (Int(value) <= 0 || Int(value) >= months.count) {
return ""
}
return months[Int(value)]
}
}
let barChartView: BarChartView = BarChartView()
xaxis.valueFormatter = IndexAxisValueFormatter(values: xAxisData)
xaxis.labelPosition = .bottom
xaxis.centerAxisLabelsEnabled = true
xaxis.granularity = 1
xaxis.drawGridLinesEnabled = false
xaxis.enabled = true
xaxis.drawGridLinesEnabled = false
xaxis.drawLabelsEnabled = true
barChartView.xAxis.axisMinimum = 0.0
barChartView.xAxis.axisMaximum = 0.0 +
chartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace) *
Double(xAxisData.count)
barChartView.xAxis.granularity = barChartView.xAxis.axisMaximum /
Double(xAxisData.count)
barChartView.data = chartData
barChartView.notifyDataSetChanged()
barChartView.setVisibleXRangeMaximum(14)
//chart animation
barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .linear)