MPAndroidChart PieChart how to set label text?

Fomove picture Fomove · Nov 17, 2016 · Viewed 13.9k times · Source

got the following code:

    Legend legend = mChart.getLegend();
    legend.setLabels(new String[]{"aaaaa", "bbbbb", "ccccc"});

This setting does not take effect Is there an other way to set the text ?

Answer

donny.rewq picture donny.rewq · Nov 24, 2016

I could not find the method setCustom(int[] color, String[] labels) in v3.0.0. Only setCustom(LegendEntry[]) for which you have to pass LegendEntry objects.

 List<LegendEntry> entries = new ArrayList<>();

 for (int i = 0; i < titleList.size(); i++) {
     LegendEntry entry = new LegendEntry();
     entry.formColor = colorList.get(i);
     entry.label = titleList.get(i);
     entries.add(entry);
 }

 legend.setCustom(entries);