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

How to make BarChart Bar Sizes proportional? #1774

Closed
patreu22 opened this issue Nov 3, 2016 · 5 comments
Closed

How to make BarChart Bar Sizes proportional? #1774

patreu22 opened this issue Nov 3, 2016 · 5 comments

Comments

@patreu22
Copy link

patreu22 commented Nov 3, 2016

I have a BarChart with two data entries and want to have the Bar parts fitting the actual percentage. So in the example 1/3 of the bar should be green and 2/3 should be red.
I can't figure out why the step from 0 to 2 is smaller than from 2 to 3.
Has anybody an idea?

My current modifications of the y-axis are these:

        barChart.leftAxis.granularity = 1
        
        let formatter = NumberFormatter()
        formatter.minimumFractionDigits = 0
        barChart.leftAxis.valueFormatter = DefaultAxisValueFormatter(formatter: formatter)

bildschirmfoto 2016-11-03 um 09 52 51

@liuxuan30
Copy link
Member

maybe you should check out ChartsDemo for those stacked bar chart to get started. I don't know how do you set it up, but it looks like wrong.

@patreu22
Copy link
Author

Well I checked the 3.0 ready Demo but the only difference is that I'm setting the granularity. Is there any way to determine the number of steps/values the left Axis should hold?

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 11, 2016

@patreu22 check computeAxisValues
I don't see any problem in your chart, have you set anything like axisMinimum?

@patreu22
Copy link
Author

patreu22 commented Nov 11, 2016

Well check the left Axis.
The red bar has the value "2" (as you can see because I printed it out), the green has the value "3".
So imho the red bar should be 2/3 of the total bar and the green part should only be 1/3.

I don't think computeAxis can help in any way.

So the problem is in the left Axis sizes. The part presenting the space between 0 and 2 is much much smaller than the one between the 2 and 3.

Any idea how to solve that?

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 15, 2016

My theory is if you set axisMinimum like 1.8, and the bar starts from 0, but only [1.8, 4] range is on the chart view, it will looks like yours. You need to check your yAxis.axisMinimum first.
It would be better if you can reproduce it with ChartsDemo.
computeAxisValues is where it calculates y axis labels range, so you get a rough idea what's your y axis minimum and maximum is and may find some clues. It can help.

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