Tuesday, November 29, 2022

[FIXED] How to change position in MPAndroidChart PieChart color indicator

Issue

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


Answered By - Shailesh Lakum
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.