Mpandroidchart: Different color of different value in LineChart?

Created on 14 Jul 2017  ·  7Comments  ·  Source: PhilJay/MPAndroidChart

Different color of different value in LineChart
hi, is there any way to do like this?
If (value < C) values.color = Black
if(value > C) values.color = RED
else values.color = YELLOW

Most helpful comment

滑动过程中字的颜色会篡行

All 7 comments

I just use setColors like this: (But I think it not a great way )

  List<Integer> colors = getColors(set1);
         set1.setValueTextColors(colors);


  /**
     * 根据level线的高低来配置不同的颜色
     *
     * @param set1
     * @return
     */
    @NonNull
    private List<Integer> getColors(LineDataSet set1) {
        List<Integer> colors = new ArrayList<Integer>();
        for (int i = 0; i < set1.getValues().size(); i++) {
            int value = (int) set1.getValues().get(i).getY();
            int color = 0;
            if (value > baseLevel) {
                color = Color.BLACK;
            } else if (value == baseLevel) {
                color = Color.RED;
            } else {
                color = Color.GREEN;
            }
            colors.add(color);
        }
        return colors;
    }


Hi, Any idea how to do that with realtime data?

滑动过程中字的颜色会篡行

@AirrWang 是的 如果是 放大了之后 滑动会出现这种情况

找不到解决办法 控件BUG?

@AirrWang 这个也不算BUG,其实本来它也没有打算实现那个功能,只是我们另寻了一个投机取巧的方法去实现,但是实现起来不算完美,只有在非放大滑动的情况下表现良好。

跟我想的一样..不懂为什么作者不写这个功能-

Was this page helpful?
0 / 5 - 0 ratings