Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I m using MPAndroidChartLibrary and facing issue when showing legend

I m using MPANdroidChartLibrary, but facing issues when showing vertical legends in the bottom of the chart. The last legend cut off.

See attached image:enter image description here

As the last legend is cut after AM registration in small devices. I follow Answer1

3: MpAndroidChart Piechart legends cutting issue at the bottom center and Answer2 posts on stack overflow but nothing works for me.

Surprisingly, This issue only comes on smaller devices even after using scroll view around the chart while on large device like above 6 inch all legends are visible properly.

like image 658
Ankur Chaudhary Avatar asked Sep 13 '25 04:09

Ankur Chaudhary


1 Answers

  1. Add as much offset as you legend grows.

    there are two methods add the specified padding at the top and bottom of the chart

    mPiecPieChart.setExtraBottomOffset(12f);//from bottom side if legends are bottom side 
    
    mPiecPieChart.setExtraTopOffset(12f);//if legends are on top side or change both if legend are on both sides
    
  2. by this line of code you can set margin between below line and legend last entry!

    legend.setYOffset(50f);
    

    as your legends increase you can increase value and on reducing legend entries you can reduce this value also!

    Legend legend = chart.getLegend();
    legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    legend.setOrientation(Legend.LegendOrientation.VERTICAL);
    legend.setDrawInside(false);
    legend.setYOffset(50f);//here value changes 
    
like image 167
Abdur Rehman Avatar answered Sep 14 '25 20:09

Abdur Rehman