如何解决在PhilJay/MPAndroidChart/issues/104下绘制线条以下的渐变?

7

github 链接

我想要一个渐变色,如果可以的话,能够选择组成颜色和方向。

这个问题解决了吗?

在此输入图片描述

1个回答

16

我发现了它的答案

LineDataSet set1 = new LineDataSet(values, "DataSet 1");
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
set1.setFillDrawable(drawable);

淡化红色.xml

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

但是填充可绘制仅支持API级别18及以上

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);
}

参考 MPAndroidChart - 链接


4
谢谢这段代码片段!为了使用渐变,我需要添加setDrawFilled(true) - Andro Chen
能否将上方的线条也设置为渐变色填充? - Dantalian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接