设置水平条形图时,我实际上遇到了一个奇怪的问题,即leftAxis的标签被剪裁了。
这是我用来设置水平条的代码
func prepareHorizontalBarChart() {
horizontalBarChartView.zoomOut()
horizontalBarChartView.fitBars = true
horizontalBarChartView.xAxis.drawGridLinesEnabled = false // disable horizontal grid lines
horizontalBarChartView.chartDescription?.enabled = false
horizontalBarChartView.xAxis.labelPosition = .bottom
horizontalBarChartView.leftAxis.spaceTop = 0.0
horizontalBarChartView.rightAxis.enabled = false
horizontalBarChartView.leftAxis.axisMinimum = 0
horizontalBarChartView.leftAxis.labelPosition = .insideChart
horizontalBarChartView.leftAxis.granularity = 1.0
horizontalBarChartView.leftAxis.granularityEnabled = true
horizontalBarChartView.extraRightOffset = 10.0
horizontalBarChartView.legend.enabled = false
horizontalBarChartView.xAxis.avoidFirstLastClippingEnabled = true
horizontalBarChartView.xAxis.granularity = 1.0
horizontalBarChartView.xAxis.granularityEnabled = true
horizontalBarChartView.xAxis.drawLabelsEnabled = true
horizontalBarChartView.rightAxis.labelFont = UIFont.systemFont(ofSize: 20)
reloadData()
}