Search code examples
pie-chartmpandroidchartindicator

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


Solution

  • <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);