How to set space between x axis labels in IOS Charts?

一曲冷凌霜 提交于 2020-01-23 03:44:06

问题


I have been facing this problem for a long time. I wish to set equal space between the x-axis labels in my ios chart. I referred to this solution and applied the code as lineChartView.xAxis.avoidFirstLastClippingEnabled = true, but it didn't work out. Then I did set the value to be false then it gave me somewhat equal spacing but now my first and last x-axis label is being hidden in the chart. Please help me out with this solution.Here is the code for the line chart customization:

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

}

These are my screenshots.

When : lineChartView.xAxis.avoidFirstLastClippingEnabled = true

When : lineChartView.xAxis.avoidFirstLastClippingEnabled = false

来源:https://stackoverflow.com/questions/44700493/how-to-set-space-between-x-axis-labels-in-ios-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!