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

CombinedChart with BarChartData cuts the first and last bars in half #323

Closed
zamith opened this issue Aug 27, 2015 · 18 comments · Fixed by PhilJay/MPAndroidChart#1007
Closed

Comments

@zamith
Copy link

zamith commented Aug 27, 2015

Everything works fine apart from the fact that the first and last bars are cut in half, this might be something that is expected, if so, how can I disable it?

Here's how it looks:

screen shot 2015-08-27 at 7 45 10

@liuxuan30
Copy link
Member

By default it should not be half.. I am not sure how much you changed? The code will leave some space for the first and last bar. I never see it on my side. You might need to provide more info. Have you changed any view port/offset properties or transformer matrix, etc. Is it zoomed or something.

You can also try your data with the ChartsDemo code to see if it is reproducible.

@zamith
Copy link
Author

zamith commented Aug 28, 2015

I haven't changed any viewport things I think, nor should it be zoomed. However, we've decided to go with a linebar, which works fine, so I'm closing this issue.

Sorry about the trouble.

@zamith zamith closed this as completed Aug 28, 2015
@liuxuan30
Copy link
Member

Well it never should be half a bar if you just setup the dataSets. If it is a bug (which I doubt), you could help provide some information.

@zamith
Copy link
Author

zamith commented Aug 28, 2015

Ok, I was able to reproduce it on the Demo. If I comment the setting of the bubbleData, the same behavior occurs:

screen shot 2015-08-28 at 3 31 59

And with the bubbleData:

screen shot 2015-08-28 at 3 32 56

@zamith zamith reopened this Aug 28, 2015
@liuxuan30
Copy link
Member

Are you using combined chart in your project? How about normal bar chart?

@zamith
Copy link
Author

zamith commented Aug 28, 2015

Yes, I was using combined chart. The normal bar chart works fine.

@liuxuan30
Copy link
Member

Ah hah, it's actually a bug. if you don't have bubble data, it will use another value to determine the chartXMin and chartXMax.

In CombinedChartView -> override func calcMinMax():

            if (self.bubbleData !== nil)
            {
                for set in self.bubbleData.dataSets as! [BubbleChartDataSet]
                {
                    let xmin = set.xMin
                    let xmax = set.xMax

                    if (xmin < chartXMin)
                    {
                        _chartXMin = xmin
                    }

                    if (xmax > chartXMax)
                    {
                        _chartXMax = xmax
                    }
                }
            }
            else
            {
//                _chartXMin = 0.0      <--- current in your code
//                _chartXMax = Double(_data.xValCount - 1)      <--- current in your code
                _chartXMin = -0.5   <--- try this
                _chartXMax = Double(_data.xVals.count) - 0.5     <--- try this
            }

You could try to use above change, if you want to use combined chart without bubbles. BTW, current combined chart just supports single bar, not grouped (I have a PR #269 for grouped support, but it's still in alpha testing :-) )

@danielgindi do you know why use 0.0 if no bubble data?

@zamith
Copy link
Author

zamith commented Aug 28, 2015

Yes, that works. Thanks.

@reeyan
Copy link

reeyan commented Aug 28, 2015

I had the same issue when I upgrade this month. Thanks for the update. Now the issue is gone.

@danielgindi
Copy link
Collaborator

Fixed thanks to @liuxuan30 :-)

@venux92
Copy link

venux92 commented Sep 15, 2016

Hi, I got the same issue actually but with a BarChart.
Is there any fix for this ?
screen shot 2016-09-15 at 6 06 51 pm

@arorajatin
Copy link

arorajatin commented Jul 11, 2017

The fix for it is adjusting the xAxis paddings.

This is my code:

let xAxisPadding = 0.45
chartView.xAxis.axisMinimum = -xAxisPadding
chartView.xAxis.axisMaximum = combinedChartData.xMax + xAxisPadding

@SentoCrespo
Copy link

Still happening on almost 2018.

@arorajatin you're a HERO, Sir 😍

@sadaf-behbahani
Copy link

@arorajatin worked for me :) Thanks <3

@liuxuan30
Copy link
Member

I have an issue seems related to this: #3186. There are some workaround and root cause I found there. feel free to check it out. I didn't come up with a good solution yet

@milosmilakovic-oviva
Copy link

This works in case when you don't have labels on x axis. If you have to print labels on x axis they won't be aligned to rounded values, but will start from -0.5 or -0.45 depending on your implementation.
xAxis.centerAxisLabelsEnabled also can't help.

@jjatie
Copy link
Collaborator

jjatie commented Mar 11, 2018

As this issue is very old, please open a new issue to report any related problems.

@ChartsOrg ChartsOrg locked and limited conversation to collaborators Mar 11, 2018
@liuxuan30
Copy link
Member

@jjatie no need, I think we already have the root cause in my #3186.

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

Successfully merging a pull request may close this issue.

10 participants