如果值大于MPAndroidChart中的常量,如何更改点颜色 [英] How to change dot colors if value is higher than constant in MPAndroidChart

查看:51
本文介绍了如果值大于MPAndroidChart中的常量,如何更改点颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果值大于3,则需要绘制红色圆圈.如何实现?我读过我应该重写方法drawCircles,但是我不知道应该在哪里做.

I need to draw red circles if value higher than 3. How to realize that? I've read that I should override method drawCircles but I dont understand where I should do this.

    LineDataSet set1;

    set1 = new LineDataSet(entries, "");
    chart.getLegend().setEnabled(false);

    set1.setColor(Color.WHITE);
    set1.setCircleColor(Color.WHITE);
    set1.setLineWidth(2f);
    set1.setCircleRadius(4f);
    set1.setValueTextSize(9f);
    set1.setValueTextColor(Color.WHITE);
    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    dataSets.add(set1); // add the datasets

    // create a data object with the datasets
    LineData data = new LineData(xVals, dataSets);
    chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
    chart.getAxisRight().setEnabled(false);
    chart.setScaleMinima(6f, 1f);
    if (measure.equals("co")) {
        LimitLine ll = new LimitLine(CO_CRITICAL, getResources().getString(R.string.critical_co));
        ll.setLineColor(Color.RED);
        ll.setLineWidth(1f);
        ll.setTextColor(Color.WHITE);
        ll.setTextSize(10f);
        chart.getAxisLeft().addLimitLine(ll);
    } else if (measure.equals("no2")) {
        LimitLine ll = new LimitLine(NO2_CRITICAL, getResources().getString(R.string.critical_no2));
        ll.setLineColor(Color.RED);
        ll.setLineWidth(1f);
        ll.setTextColor(Color.WHITE);
        ll.setTextSize(10f);
        chart.getAxisLeft().addLimitLine(ll);
    }

    // set data
    chart.setData(data);

推荐答案

尝试一下:

定义一个ArrayList:

ArrayList<Integer> color = new ArrayList<>();

并将您的条件添加为:

if (YOUR_CONDITION) {
    color.add(ColorTemplate.rgb("#f8bf94"));
    yVals1.add(new Entry(VALUE, COUNTER));
} else {
    color.add(ColorTemplate.rgb("#e0e0e0"));
    yVals1.add(new Entry(VALUE, COUNTER));
}

在添加数据集之前,添加

And before adding dataset, add

set1.setColors(color);

作为参考,您可以检查链接.

希望这个答案对您有帮助.

For your reference, you can check this link.

Hope this answer will help you.

这篇关于如果值大于MPAndroidChart中的常量,如何更改点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆