Daniel Kim
Daniel Kim

Reputation: 27

MPAndroidChart I'd like to change the color of the graph at the top of the limit line

I'd like to change the color of the graph at the top of the limit line. We've now implemented changing the color of chart bars across the limit line. But what I want to do is change the color of the chart where it crosses the limit line.

enter image description here

enter image description here

Upvotes: 0

Views: 396

Answers (1)

Joan
Joan

Reputation: 356

I'm assuming you are using a BarChart here

It turns out that this response was addressing your needs, maybe I can try to clarify a bit more:

It seems that a normal BarChart data no longer suits your need. In order to stack different colours in the same bar, you'll need what's called a StackedBarChart

For using the aforementioned StackedBarChart (which is almost the same as the BarChart) you need to adapt the data and the colours for the data:

  • The data: Now, for each bar you will need to add two values that will be painted differently
    • The Y value below the limit -> let's call it A
    • The Y value above the limit -> let's call it B

So here, A value cannot be higher than your limit. Let's give an example:

Limit = 10  
Total value = 12  
A = 10  
B = 2  

Then, you should input your data as follows (assuming the first bar starts at X=0):

BarEntry stackedEntry = new BarEntry(0f, new float[] { 10, 2 });
  • The colours: Once you've set the data, you just need to say the colours of each part of the Bar. Your bar will have two different colours, so the code should be something similar to this:

dataSet.color = listOf(LightBlue, Darkblue) (kotlin code)

The dataSet here, is the object with all the BarEntries we have defined above.

I hope this clarifies and solves your needs, good luck :)

Upvotes: 1

Related Questions