I have attached the screenshot of my usage chart. In red box display the legends and they are cutting in pie chart. Below is my code:
i have solved this issue by adding the titles in normal list view
ListView list = (ListView) findViewById(R.id.list_chart);
list.setAdapter(new ChartTextLegendAdapter(this, values, colors));
and hide the titles within Legend
this is my layout XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@color/background_color">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="300dp" />
<ListView
android:id="@+id/list_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/chart1" />
</RelativeLayout>
and dont forgot to pass the values and ArrayList of colors manully
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
values.DetailAmount = getIntent().getStringArrayListExtra("amount");
values.DetailId = getIntent().getIntegerArrayListExtra("id");
values.DetailName = getIntent().getStringArrayListExtra("names");
values.DetailEnglishName = getIntent().getStringArrayListExtra("enames");
month_name = getIntent().getStringExtra("month_name");
hope this will solve your issue too.
have you tried customizing with xml attribute android:translationY="-10dp"
?
OR view.setExtraOffsets(...);
you can manage dp
accordingly.
UPDATE
l.setYOffset(10f);
Most probably there is an issue with the chart offsets. Try this, should solve your problem
pieChart.setExtraOffsets(0, 0, 0, 25);
This function sets extra offsets (around the chart view) to be appended to the auto-calculated offsets. The arguments are (left, top, right, bottom). Play around with the values to see which offsets suits your needs.
Try to set padding or margin to PieChart , Or maybe align legend in horizontal direction.