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

BarChartView: xAxis values are not aligned with bars #2106

Closed
SvenMuc opened this issue Jan 22, 2017 · 10 comments
Closed

BarChartView: xAxis values are not aligned with bars #2106

SvenMuc opened this issue Jan 22, 2017 · 10 comments

Comments

@SvenMuc
Copy link
Contributor

SvenMuc commented Jan 22, 2017

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.

bildschirmfoto 2017-01-22 um 19 06 29

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.

bildschirmfoto 2017-01-22 um 19 16 36

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

bildschirmfoto 2017-01-22 um 19 24 59

**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.

bildschirmfoto 2017-01-22 um 19 30 14

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?

@SvenMuc
Copy link
Contributor Author

SvenMuc commented Jan 22, 2017

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

bildschirmfoto 2017-01-22 um 19 55 57

@SvenMuc
Copy link
Contributor Author

SvenMuc commented Jan 22, 2017

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

bildschirmfoto 2017-01-22 um 20 06 19

@deepakthumbmunkeys
Copy link

@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

@ryanwaggoner
Copy link

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

@poojab
Copy link

poojab commented Oct 24, 2019

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?

@bejeri4
Copy link

bejeri4 commented Oct 25, 2019

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)

@bejeri4
Copy link

bejeri4 commented Oct 28, 2019

barChart.xAxis.centerAxisLabelsEnabled = false
this fixed in my case.
Do not set centerAxisLabelsEnabled true

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 29, 2019

refer charts demo. this has been long.. so should be invalid now.

@poojab
Copy link

poojab commented Oct 30, 2019

chartView.xAxis.axisMinimum = -0.5 //to avoid issue of last bar getting half cut

this worked for me

@Khushtar786
Copy link

Can Any One Give me the Whole Code of the Graph Actually I Applied These But Didn't Work

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

7 participants