如何在带有mpAndroidChart的Combinedchart中绘制线条的渐变?

时间:2019-05-24 06:29:40

标签: android mpandroidchart combinedchart

如何使用mpAndroidChart在组合图表中为折线绘制渐变,就像来自this question的图像一样? 我尝试通过库中的setGradientColor()方法设置渐变:

dataSet.setGradientColor(ContextCompat.getColor(getContext(), R.color.dark_slate_blue),
                ContextCompat.getColor(getContext(), R.color.macaroniAndCheese));

此外,我尝试实现with render,但是它不起作用

预期结果: enter image description here

1 个答案:

答案 0 :(得分:0)

chart_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#cc0033"
        android:endColor="#DD1144" />
</shape>

MainActivity.java

set1.setDrawFilled(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
    // 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);
}
相关问题