Si prega di cercare la risposta data MPAndroidChart - Legend labels are being cut off. Ho già fornito la risposta in base al tuo problema. Cerca il codice che ti sarà sicuramente d'aiuto. Si dovrà implementare leggende personalizzate con i loro colori leggende e le etichette seguendo le istruzioni riportate di seguito:
Fase 1
Legend legend = mChart.getLegend();
Fase 2
int colorcodes[] = legend.Colors();
Passi 3
for (int i = 0; i < legend.Colors().length-1; i++) {
.....
.....
}
Passi 4
allora si dovrà prendere un layout orizzontale o verticale e ottenere i codici di colore leggende e leggende etichetta e in base alla lunghezza leggende creare il layout e l'etichetta. Esempio di codice è il seguente:
LinearLayout.LayoutParams parms_left_layout = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
parms_left_layout.weight = 1F;
LinearLayout left_layout = new LinearLayout(context);
left_layout.setOrientation(LinearLayout.HORIZONTAL);
left_layout.setGravity(Gravity.CENTER);
left_layout.setLayoutParams(parms_left_layout);
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]);
left_layout.addView(legend_layout);
TextView txt_unit = new TextView(context);
txt_unit.setText(legend.getLabel(i));
left_layout.addView(txt_unit);
LinearLayout.LayoutParams parms_middle_layout = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
parms_middle_layout.weight = 1F;
LinearLayout middle_layout = new LinearLayout(this);
middle_layout.setOrientation(LinearLayout.HORIZONTAL);
middle_layout.setGravity(Gravity.CENTER);
middle_layout.setLayoutParams(parms_middle_layout);
TextView txt_leads = new TextView(this);
txt_leads.setText("450");
middle_layout.addView(txt_leads);
LinearLayout.LayoutParams parms_right_layout = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
parms_right_layout.weight = 1F;
LinearLayout right_layout = new LinearLayout(this);
right_layout.setOrientation(LinearLayout.HORIZONTAL);
right_layout.setGravity(Gravity.CENTER);
right_layout.setLayoutParams(parms_right_layout);
TextView txt_leads_percentage = new TextView(this);
txt_leads_percentage.setText(munit_percentage_list.get(i) + "");
right_layout.addView(txt_leads_percentage);
childlayout.addView(left_layout);
childlayout.addView(middle_layout);
childlayout.addView(right_layout);
E dopo questo aggiungere il vostro (layout di bambino che si è creato in fase di esecuzione) per il layout principale.
fonte
2015-03-19 13:28:20
c'è un array che ha anche le percentuali? –