在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);