I migrated my diagrams to Charts 3.0.1. It worked quite smoothly, but I cannot manage to align the bar charts to my xAxis values. The following diagram should show a histogram of values between 0 and 10 (11 bars).
Variant 1
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.setLabelCount(11, force: true)
All index values are shown, but not aligned with the bars.

Variant 2 (centerAxisLabelsEnabled)
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.centerAxisLabelsEnabled = true
barChart.xAxis.setLabelCount(11, force: true)
The index 10 is missing on the xAxis.

Variant 3 (fitBars)
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.centerAxisLabelsEnabled = true
barChart.xAxis.setLabelCount(11, force: true)
barChart.fitBars = true
The xAxis starts with -1

**Variant 4 (axisMinimum and axisMaximum)
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.centerAxisLabelsEnabled = true
barChart.xAxis.setLabelCount(11, force: true)
barChart.xAxis.axisMinimum = 0.0
barChart.xAxis.axisMaximum = 10.0
barChart.fitBars = true
The bars are not centered any more and the last xAxis value 10 is not shown.

I tried a couple of other combinations but was not able to align the bars with my numbers 0...10 on the xAxis. Someone has any idea?
Another trial. Looks close to my expected result, but the first an last bars are shown only half (see also isst #2105).
barChart.xAxis.axisMinimum = 0.0
barChart.xAxis.axisMaximum = 10.0
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.labelCount = 11
barChart.fitBars = true

The closest diagram layout compared to Charts 2.x gives me the following code. But how can I move the gridlines between the bars as it is done in Charts 2.x? I tried xAxis.centerAxisLabelsEnabled = true and fitBars = true. Both attributes corrupted my xAxis/bar layout.
barChart.xAxis.granularity = 1.0
barChart.xAxis.granularityEnabled = true
barChart.xAxis.labelCount = 11

@SvenMuc I'm also facing the same issue with Combined Chart (Bar and Line chart)... First and Last bar width is just half.. if you found the solution please help me out
For anyone else struggling with this, I found that I couldn't use this combination of granularity and setLabelCount() or labels would be misaligned and/or left & right bars cut off.
However, this seems to work for me:
self.periodGraphView.xAxis.labelCount = barValues.count
self.periodGraphView.xAxis.spaceMin = 0.5
self.periodGraphView.xAxis.spaceMax = 0.5
self.periodGraphView.xAxis.granularityEnabled = true
self.periodGraphView.xAxis.granularity = 1
Hey Thanks this helped me to get x axis labels centre to the bar but how about last bar getting cut?
How you fixed it?
Hey Thanks this helped me to get x axis labels centre to the bar but how about last bar getting cut?
How you fixed it?
barChart.xAxis.axisMaximum = Double(values.count)
barChart.xAxis.centerAxisLabelsEnabled = false
this fixed in my case.
Do not set centerAxisLabelsEnabled true
refer charts demo. this has been long.. so should be invalid now.
chartView.xAxis.axisMinimum = -0.5 //to avoid issue of last bar getting half cut
this worked for me
Can Any One Give me the Whole Code of the Graph Actually I Applied These But Didn't Work
Most helpful comment
For anyone else struggling with this, I found that I couldn't use this combination of granularity and setLabelCount() or labels would be misaligned and/or left & right bars cut off.
However, this seems to work for me: