PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.52k stars 9.01k forks source link

Different color of different value in LineChart? #3256

Open fly7632785 opened 7 years ago

fly7632785 commented 7 years ago

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

fly7632785 commented 7 years ago

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;
    }
lonewolf9277 commented 7 years ago

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

Arthur185 commented 6 years ago

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

fly7632785 commented 6 years ago

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

Arthur185 commented 6 years ago

找不到解决办法 控件BUG?

fly7632785 commented 6 years ago

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

heyleon commented 6 years ago

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