MPAndroidChart fill color gradient

白昼怎懂夜的黑 提交于 2019-11-30 09:27:01

You can use the following two methods:

LineRadarDataSet#setDrawFilled(boolean isFilled); 
LineRadarDataSet#setFillDrawable(Drawable d);

Here's a link to the javadoc for that class.

This is the example from the MPAndroidChart sample project:

set1.setDrawFilled(true);
if (Utils.getSDKInt() >= 18) {
    // fill drawable only supported on api level 18 and above
    Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
    set1.setFillDrawable(drawable);
}
else {
    set1.setFillColor(Color.BLACK);
}

In fade_red.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:startColor="#00ff0000"
        android:endColor="#ffff0000" />
</shape>

Here's a sample of what it looks like on a LineChart:

Okay i have found a solution:

William Chart and i am using this method:

int[] colors = { getResources().getColor(R.color.menu_text),
 getResources().getColor(android.R.color.white) };

float[] index = { 0, 1 };
dataset.setGradientFill(colors, index);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!