'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
Solution 1:[1]
<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);
Solution 2:[2]
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);
Solution 3:[3]
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.RIGHT_OF_CHART;
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shailesh Lakum |
Solution 2 | Harry Mad |
Solution 3 | Tyler2P |