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

Is it possible to set color of bar based on values of X axis for a horizontal bar graph? #2236

Closed
PreetanjaliR opened this Issue Sep 6, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@PreetanjaliR

PreetanjaliR commented Sep 6, 2016

No description provided.

@iRuth

This comment has been minimized.

iRuth commented Sep 6, 2016

If you know the color of each bar, you could specify those colors and set the BarDataSet; since colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array.

For example:

    BarDataSet barDataSet = new BarDataSet(yValues, "");

    barDataSet.setColors(barColors);

where barColors is the list of colors to be used by the bar chart's bars.

@PreetanjaliR

This comment has been minimized.

PreetanjaliR commented Sep 7, 2016

@iRuth Hi! What I intend to do is, I want the bar to be coloured red if the value of X is, say between a specific range or coloured green for a different range. Can something like this be achieved with MPAndroid?

@iRuth

This comment has been minimized.

iRuth commented Sep 7, 2016

@PreetiR08, yes you can achieve that with this library. You need to specify a list of colors that would be used by your list of X values. So if you have 10 X values, for each value of X, you would populate your list of colors with either a green, a red or whatever color you need. This ensures that the index of the X value in the list of X values matches with the index of the color in the list of colors. And then set the colors on your barDataSet as I indicated above (barDataSet.setColors(barColors);).

@PreetanjaliR

This comment has been minimized.

PreetanjaliR commented Sep 8, 2016

@iRuth Thanks! That worked! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment