在 MPAndroidChart 中设置饼图切片颜色 [英] Setting the pie slice colors in MPAndroidChart

查看:47
本文介绍了在 MPAndroidChart 中设置饼图切片颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为饼图中的每个切片定义特定的十六进制值.

I need to define specific hex values for each slice in my pie chart.

我正在关注 wiki 但该方法似乎没有正在为 PieDataSet

I'm following the wiki but the method doesn't seem to be working for PieDataSet

PieDataSet dataSet = new PieDataSet(entries, "Fuel");
dataSet.setColors(new int[] { R.color.green1, R.color.green2, R.color.green3, R.color.green4 }, Context);

显示这些错误:

Cannot resolve symbol 'green1'

Expression expected  <-- At the 'Context'

是否有其他方法可以设置饼图切片颜色?这似乎适用于折线图,但不适用于饼图.

Is there an alternate way to set the pie slice color? This seems to work for Line charts but not for pie.

推荐答案

找到了解决方法:

final int[] MY_COLORS = {Color.rgb(192,0,0), Color.rgb(255,0,0), Color.rgb(255,192,0),
                                Color.rgb(127,127,127), Color.rgb(146,208,80), Color.rgb(0,176,80), Color.rgb(79,129,189)};
                        ArrayList<Integer> colors = new ArrayList<Integer>();

                        for(int c: MY_COLORS) colors.add(c);

                        dataSet.setColors(colors);

这篇关于在 MPAndroidChart 中设置饼图切片颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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