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

Avoid that the last label entry in the x-labels "clip" off the edge of the screen #3819 #3820

Merged
merged 1 commit into from
May 2, 2018

Conversation

longup
Copy link

@longup longup commented Feb 27, 2018

Modified the “drawLabels” methon in class XAxisRenderer, i should be i/2 in line 210, so the last label can be handled correctly.

@longup
Copy link
Author

longup commented Mar 12, 2018

Please review this commit and merge to fix this bug, thank you.

@AliGolmirzaei
Copy link

I have the same issue and I think this is the fix. please review it. thank you

@almic
Copy link
Contributor

almic commented Apr 29, 2018

This bug is not caused by the XAxisRenderer. The value you changed, i to i / 2 is checking if the current drawn label is the last label, and if so, it correctly shifts it back width / 2, since the label is already centered and only half clips off.

Please use xAxis.setAvoidFirstLastClipping(true). If that still doesn't fix the problem, you can simply increase the visible X range with xAxis.axisMaximum(float), just add 0.5f or similar to the last X value.

~ nothing to see here ~

@almic almic closed this Apr 29, 2018
@longup
Copy link
Author

longup commented May 2, 2018

Hello, I have use xAxis.setAvoidFirstLastClipping(true) and increase the visible X range with xAxis.axisMaximum(float), but it crash, like this:
float lastValue = lineChart.getXAxis().getAxisMaximum(); lineChart.getXAxis().setAxisMaximum(lastValue + 1.0f);

And I have try a lot of values, but it doesn't work. Only if I changed the value i to i / 2, it worked fine.

Thank you,please review it.

@almic
Copy link
Contributor

almic commented May 2, 2018

I just double-checked, and it looks like I was wrong. Line 199 sneaked by!

Anyway, this change looks correct, as the point array is always going to be double the size of mXAxis.mEntryCount, it needs to be divided by 2 when checking for the last entry. Thanks for contributing!

Merging.

@almic almic reopened this May 2, 2018
@almic almic merged commit 640208c into PhilJay:master May 2, 2018
regas99 pushed a commit to regas99/MPAndroidChart that referenced this pull request Apr 1, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants