问题
I am using MPchart piechart. When i set custom legend arrays it not accepting that array.
My code...
Legend l = chart.getLegend();
l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "aaaaa", "bbbbb", "ccccc"});
Error...
Cannot resolve method 'setCustom(int[],java.lang.String[])'
My MPchart version : v3.0.0
How can i resolve this issue.?
回答1:
This worked for me to set a custom legend:
// Use Legend Entry
LegendEntry l1=new LegendEntry("Bank", Legend.LegendForm.DEFAULT,10f,2f,null, Color.RED);
LegendEntry l2=new LegendEntry("Chitfund", Legend.LegendForm.CIRCLE,10f,2f,null, Color.GREEN);
LegendEntry l3=new LegendEntry("Mobile", Legend.LegendForm.LINE,10f,1f,null,Color.BLACK);
LegendEntry l4=new LegendEntry("Internet", Legend.LegendForm.DEFAULT,10f,2f,null, Color.BLUE);
LegendEntry l5=new LegendEntry("ATM", Legend.LegendForm.DEFAULT,10f,2f,null, Color.DKGRAY);
LegendEntry l6=new LegendEntry("Check", Legend.LegendForm.SQUARE,10f,1f,null,Color.CYAN);
Legend l=piechart.getLegend();
l.setCustom(new LegendEntry[]{l1,l2,l3,l4,l5,l6});
//For set the same color to chart
piedataSet.setColors(new int[]{Color.RED, Color.GREEN, Color.BLACK, Color.BLUE, Color.DKGRAY, Color.CYAN});//Color is set based on your Legend entry color
Explanation of Legend Entry Parameters:
LegendEntry l1=new LegendEntry("Bank", Legend.LegendForm.DEFAULT,10f,2f,null, Color.RED);
Parameter Example
--------------------------------------------------------
legend label - "Bank"
legend form - Legend.LegendForm.DEFAULT[ (DEFAULT Shape is Square) Default instead of any (like Square, circle, line)]
formsize - 10f,2f [height of the width]
dashboard effect - null
color - Color.RED
回答2:
working for me try this
add color to string array
String[] array;
array = new String[<**size of your color arraylist**>];
for (int i = 0; i < **size of your color arraylist**; i++) {
array[i] = **color arraylist**.get(i);
}
set custom color
if (array.length > 0 && array !=null) {
l.setCustom(l.getColors(), array);
}
来源:https://stackoverflow.com/questions/42802952/android-mpchart-piechart-legend-setcustom-error