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