饼图图例颜色未更新 mpandroidchart
Pie chart legend colours are not being updated mpandroidchart
在MpAndroidChart中使用饼图,成功绘制出饼图。当尝试向 chart.Label 的图例添加自定义标签和颜色时,正在更新,但所有图例的图例颜色均为蓝色。
ArrayList<String> PieEntryLabels = new ArrayList<>();
PieEntryLabels.add("January");
PieEntryLabels.add("February");
PieEntryLabels.add("March");
PieEntryLabels.add("April");
List<LegendEntry> legendEntries = new ArrayList<>();
int[] colorList = new int[] { R.color.graphcolor1, R.color.graphcolor2,R.color.graphcolor3,R.color.graphcolor4};
pieDataSet.setColors(colorList, context);
for (int i = 0; i < PieEntryLabels.size(); i++) {
LegendEntry entry = new LegendEntry();
entry.formColor =colorList[i];
entry.label = PieEntryLabels.get(i);
legendEntries.add(entry);
}
pieChart.getLegend().setCustom(legendEntries);
尝试将强调色或原色的十六进制代码更改为您在 colors.xml 中所需的颜色。
解决了我通过以下方式添加颜色列表时的问题
int[] colorList = new int[]{Color.parseColor("#C570C5"),
Color.parseColor("#E0A2E0"),
Color.parseColor("#DDBFDD"),
Color.parseColor("#E7D7E7")};
在MpAndroidChart中使用饼图,成功绘制出饼图。当尝试向 chart.Label 的图例添加自定义标签和颜色时,正在更新,但所有图例的图例颜色均为蓝色。
ArrayList<String> PieEntryLabels = new ArrayList<>();
PieEntryLabels.add("January");
PieEntryLabels.add("February");
PieEntryLabels.add("March");
PieEntryLabels.add("April");
List<LegendEntry> legendEntries = new ArrayList<>();
int[] colorList = new int[] { R.color.graphcolor1, R.color.graphcolor2,R.color.graphcolor3,R.color.graphcolor4};
pieDataSet.setColors(colorList, context);
for (int i = 0; i < PieEntryLabels.size(); i++) {
LegendEntry entry = new LegendEntry();
entry.formColor =colorList[i];
entry.label = PieEntryLabels.get(i);
legendEntries.add(entry);
}
pieChart.getLegend().setCustom(legendEntries);
尝试将强调色或原色的十六进制代码更改为您在 colors.xml 中所需的颜色。
解决了我通过以下方式添加颜色列表时的问题
int[] colorList = new int[]{Color.parseColor("#C570C5"),
Color.parseColor("#E0A2E0"),
Color.parseColor("#DDBFDD"),
Color.parseColor("#E7D7E7")};