Sergey Gamayunov Sergey Gamayunov - 22 days ago 15
Swift Question

Horizontal bar chart doesn't start at 0

Sample Chart

When I provide data for Bar Chart it appears with little offset. I thought about stacked Bar Chart, but it was wrong - that how I provide sample data for chart:

var barEntries = [BarChartDataEntry]()
barEntries.append(BarChartDataEntry(x: 0, y: 0))
barEntries.append(BarChartDataEntry(x: 4, y: 1))
barEntries.append(BarChartDataEntry(x: 8, y: 24))
barEntries.append(BarChartDataEntry(x: 12, y: 37))
barEntries.append(BarChartDataEntry(x: 16, y: 27))
barEntries.append(BarChartDataEntry(x: 20, y: 11))

let barDataSet = BarChartDataSet(values: barEntries, label: nil)
let barData = BarChartData(dataSet: barDataSet)
barData.barWidth = 4
barChartView.data = barData


All
barEntries
was created with
BarChartDataEntry
initializers for non-stacked bar. Now I have no idea why bar doesn't start at 0.

Answer

try set yAxis.axisMinimum = 0. Check ChartsDemo.