Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change position in MPAndroidChart PieChart color indicator

I am working on MPAndroidChart and I want to change position of PieChart color indicator.

<com.github.mikephil.charting.charts.PieChart
    android:id="@+id/chart"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center" />

When i set android:layout_width="200dp" and android:layout_height="200dp" It apply height and width whole view.

I want to only make distance between PieChart and its color indicator. Don't want to overlap indicator on PieChart View

enter image description here

enter image description here

like image 700
Palak Avatar asked Oct 28 '25 17:10

Palak


2 Answers

<com.github.mikephil.charting.charts.PieChart
        android:id="@+id/chart1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.LEFT_OF_CHART);
        l.setXEntrySpace(7f);
        l.setYEntrySpace(5f);
        l.setYOffset(0f);

OR

Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
        l.setXEntrySpace(7f);
        l.setYEntrySpace(5f);
        l.setYOffset(0f);
like image 129
Shailesh Lakum Avatar answered Oct 31 '25 11:10

Shailesh Lakum


You can set position of color indicators like LegendPosition.RIGHT_OF_CHART,LegendPosition.BELOW_CHART_LEFT etc.

Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.RIGHT_OF_CHART);
        l.setXEntrySpace(7f);
        l.setYEntrySpace(5f);
like image 32
Harry Mad Avatar answered Oct 31 '25 12:10

Harry Mad