我一直面对这个问题。我希望在我的ios图表中的x轴标签之间设置相等的空间。我提到了this解决方案并将代码应用为lineChartView.xAxis.avoidFirstLastClippingEnabled = true
,但它没有成功。然后我确实将值设置为false
然后它给了我一些相等的间距,但现在我的第一个和最后一个x轴标签被隐藏在图表中。请帮我解决这个问题。这是线图自定义的代码:
func setXaxis(){
lineChartView.xAxis.labelPosition = .bottom
lineChartView.xAxis.avoidFirstLastClippingEnabled = false
lineChartView.xAxis.forceLabelsEnabled = true
lineChartView.xAxis.labelPosition = XAxis.LabelPosition.bottomInside
lineChartView.xAxis.drawGridLinesEnabled = false
lineChartView.xAxis.labelTextColor = chartcolor
lineChartView.xAxis.labelCount = 6
lineChartView.xAxis.xOffset = 10
}
func setYaxis(){
lineChartView.leftAxis.labelPosition = YAxis.LabelPosition.insideChart
lineChartView.leftAxis.labelTextColor = chartcolor
lineChartView.leftAxis.gridColor = chartcolor
lineChartView.leftAxis.labelCount = 5
lineChartView.leftAxis.yOffset = 6
lineChartView.setViewPortOffsets(left: 0, top: 0, right: 0, bottom: 0)
}
func setChart(){
lineChartView.noDataText = ""
lineChartView.dragEnabled = false
lineChartView.setScaleEnabled(false)
lineChartView.pinchZoomEnabled = false
lineChartView.drawMarkers = true
lineChartView.backgroundColor = bluecolor
lineChartView.rightAxis.enabled = false
lineChartView.legend.enabled = false
lineChartView.chartDescription?.enabled = false
}
这些是我的截图。
何时: lineChartView.xAxis.avoidFirstLastClippingEnabled = true
何时: lineChartView.xAxis.avoidFirstLastClippingEnabled = false