0

I want to set multiple background colors in a chart view. A single color can be set in a background of the chart view but there is no way to set multiple colors.

Percentage-wise wants to add background color 0% to 20% - Red color, 21% to 60% - White and 61% to 100% in green colorenter image description here

1 Answers1

0

Did you try using a layer-list for the background? Something like this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/green" />
    </shape>
</item>

<item android:top="400dp">
    <shape
        android:shape="rectangle">
        <solid android:color="@color/white" />
        <size android:height="100dp"/>
    </shape>
</item>

<item android:top="600dp">
    <shape
        android:shape="rectangle">
        <solid android:color="@color/red" />
        <size android:height="200dp"/>
    </shape>
</item>

</layer-list>

I think that if you want an actual percentage you'll need to calculate it yourself. see this answer -> link

Geeky bean
  • 475
  • 6
  • 21
  • I tried with layer list.. but color is going out of the chart and i want change the Bg color dynamically based on percentage values. – Manoj Gowda Feb 26 '20 at 14:48
  • I understand, try the approach in the link I mentioned, I think that's what you need. Good luck :) – Geeky bean Feb 26 '20 at 20:04