Mpandroidchart: Getcolors() Is Now Deprecated For 'legend'. What Should I Use Instead?
I'm displaying a custom legend for a PieChart in MPAndroidChart however, .getColors() and .getLabels() are now deprecated. I've been using them to get an int array and string array
Solution 1:
The Legend
class now follows better OOP practices and is composed of an array of LegendEntry
. You can iterate through each and extract the colors or the labels as you wish.
private int [] getColors(Legend legend) {
LegendEntry [] legendEntries = legend.getEntries();
int [] colors = new int[legendEntries.length];
for (int i = 0; i < legendEntries.length; i++) {
colors[i] = legendEntries[i].formColor;
}
return colors;
}
private String [] getLabels(Legend legend) {
LegendEntry [] legendEntries = legend.getEntries();
String [] labels = new String[legendEntries.length];
for (int i = 0; i < legendEntries.length; i++) {
labels[i] = legendEntries[i].label;
}
return labels;
}
Post a Comment for "Mpandroidchart: Getcolors() Is Now Deprecated For 'legend'. What Should I Use Instead?"