Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal bar chart doesn't start at 0 #1827

Closed
SergeyGamayunov opened this issue Nov 14, 2016 · 2 comments
Closed

Horizontal bar chart doesn't start at 0 #1827

SergeyGamayunov opened this issue Nov 14, 2016 · 2 comments

Comments

@SergeyGamayunov
Copy link

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.

2016-11-11_12-59-51

PS I asked the same question in stackoverflow.com - you can provide your answer anywhere you want, here's the link: http://stackoverflow.com/questions/40545768/horizontal-bar-chart-doesnt-start-at-0

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 15, 2016

try set yAxis.axisMinimum = 0. Check ChartsDemo.

@SergeyGamayunov
Copy link
Author

Thanks, you're almost right.

To move all bars to zero, we need set both:

barChartView.rightAxis.axisMinimum = 0.0
barChartView.leftAxis.axisMinimum = 0.0

It seems a little strange because as you can see I switched off left axis (actually with horizontal bar chart it is "top" axis)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants