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

Diffrent X-axis label color #921

Closed
amitvyawahare opened this issue Apr 5, 2016 · 3 comments
Closed

Diffrent X-axis label color #921

amitvyawahare opened this issue Apr 5, 2016 · 3 comments

Comments

@amitvyawahare
Copy link

Is there any way to use different color for different XAxis data point ? I know we can do this for Y-Axis using chartDataSet.valueColors = valueColors

Is there any similar function for XAxis ?

@liuxuan30
Copy link
Member

No, and you have to do it yourself and you are more than welcome to file a PR with a clean design :)
btw, the data set value colors is for the chart value labels, not y axis itself.
x and y axis only support one labelTextColor

@Sethmr
Copy link

Sethmr commented Nov 3, 2016

If you absolutely have to change the xAxis colors, here is where the magic happens. Although you would have to change it every time you update the code. I found it inside XAxisRendererHorizontalBarChart. I am sure there is something similar for other charts.

if viewPortHandler.isInBoundsY(position.y)
            {
                if let label = xAxis.valueFormatter?.stringForValue(xAxis.entries[i], axis: xAxis)
                {

                    //--vvv--I ADDED THIS CODE---vvv---
                    var color: UIColor!
                    if label == "This String" || label == "That String" || label == "These Strings" {
                        color = UIColor(red: 0/255, green: 64/255, blue: 135/255, alpha: 1/1)
                    } else {
                        color = UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1/1)
                    }

                    drawLabel(
                        context: context,
                        formattedLabel: label,
                        x: pos,
                        y: position.y,
                        attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: color],
                        anchor: anchor,
                        angleRadians: labelRotationAngleRadians)
                    //--^^^--I ADDED THIS CODE---^^^---

                    //--vvv--OLD CODE---vvv---
//                    drawLabel(
//                        context: context,
//                        formattedLabel: label,
//                        x: pos,
//                        y: position.y,
//                        attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor],
//                        anchor: anchor,
//                        angleRadians: labelRotationAngleRadians)
                }
            }

@Sethmr
Copy link

Sethmr commented Nov 3, 2016

I'm considering writing something for this, because I have to familiarize myself with this code so much anyhow for my job. I just need to learn common protocols for contributing to git projects.

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

3 participants