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 xAxis limit-labels display in a one-bar BarChart. #2771

Closed
guillaumejounel opened this issue Sep 5, 2017 · 1 comment
Closed

Avoid xAxis limit-labels display in a one-bar BarChart. #2771

guillaumejounel opened this issue Sep 5, 2017 · 1 comment

Comments

@guillaumejounel
Copy link

guillaumejounel commented Sep 5, 2017

Hi, I have the following HorizontalBarChart :
screen shot 2017-09-05 at 15 24 45
Everything works fine, my only problem is when I have only one bar:
screen shot 2017-09-05 at 15 30 04
Any idea of how to get rid of these 2 limit-labels?
Thank you very much!

@guillaumejounel
Copy link
Author

guillaumejounel commented Sep 6, 2017

Probably not the best way to do it, but it works:
Actually, xAxis.entryCount (used to draw the labels) is set to 3 when xAxis.labelCount equals 1, so basically I've overloaded the drawLabels() function of my XAxisRenderer and added the following condition to draw the labels : xAxis.entryCount == xAxis.labelCount || i == 1, so that indexes 0 and 2 are not drawn when there is only one bar. Here is the concerned part of the function:

if viewPortHandler.isInBoundsY(position.y) {
    if let label = xAxis.valueFormatter?.stringForValue(xAxis.entries[i], axis: xAxis) {
        if xAxis.entryCount == xAxis.labelCount || i == 1 {
            drawLabel(
                context: context,
                formattedLabel: label,
                x: pos,
                y: position.y,
                attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor],
                anchor: anchor,
                angleRadians: 0)
            }
        }
    }
}

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

1 participant