I have create piechart using MpAndroidChart and data is retrieved from firebase.I need to display custom legends but only one item is displaying but pieChart has more than 5items.Since getColor() and getLabels() are deprecated and i have used this Code to get color and label of piechart
listdataref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
Log.d("TAG", "IF else");
/* new homePieTask().execute(dataSnapshot);*/
ArrayList<PieEntry> entries = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
int total = ds.child("total").getValue(Integer.class);
String name = ds.child("expensesName").getValue(String.class);
entries.add(new PieEntry(total, name));
}
pieDataSet = new PieDataSet(entries,"Expense By Dates");
pieData= new PieData(pieDataSet);
homepiechart.setData(pieData);
pieDataSet.setColors(color);
Legend legend = homepiechart.getLegend();
legend.setEnabled(false);
int colorCodes[] = getColors(legend);
String labels[] = getLabels(legend);
for (int i = 0; i < getColors(legend).length -1; i++) {
LinearLayout.LayoutParams parms_legen_layout = new LinearLayout.LayoutParams(
20, 20);
parms_legen_layout.setMargins(0, 0, 20, 0);
LinearLayout legend_layout = new LinearLayout(context);
legend_layout.setLayoutParams(parms_legen_layout);
legend_layout.setOrientation(LinearLayout.HORIZONTAL);
legend_layout.setBackgroundColor(colorCodes[i]);
relativeLayout.addView(legend_layout);
TextView txt_unit = new TextView(context);
txt_unit.setText(labels[i]);
relativeLayout.addView(txt_unit);
}