【问题标题】:Pie chart legend colours are not being updated mpandroidchart饼图图例颜色未更新 mpandroidchart
【发布时间】:2020-06-22 07:04:10
【问题描述】:

在MpAndroidChart中使用饼图.was成功地能够绘制饼图。当尝试将自定义标签和颜色添加到图表的图例时。标签正在更新,但所有图例的图例颜色都变为蓝色。

   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文件吗?

标签: java android mpandroidchart


【解决方案1】:

尝试在 colors.xml 中将颜色重音或原色的十六进制代码更改为您所需的颜色。

【讨论】:

    【解决方案2】:

    解决了我通过以下方式添加颜色列表时的问题

        int[] colorList =  new int[]{Color.parseColor("#C570C5"),
                Color.parseColor("#E0A2E0"),
                Color.parseColor("#DDBFDD"),
                Color.parseColor("#E7D7E7")};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多