Show image instead of text in MPAndroidChart pie chart

1.7k Views Asked by At

I have a pie chart in my android application that i draw with MPAndroidChart.

 <com.github.mikephil.charting.charts.PieChart
        android:id="@+id/chart"
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:layout_centerInParent="true"
        />

 PieDataSet pieDataSet = new PieDataSet(entries, "expenses");
        pieDataSet.setColors(ColorTemplate.PASTEL_COLORS);
        pieDataSet.setDrawValues(false);

        PieData data = new PieData(xValues, pieDataSet);

        chart.setData(data);
        chart.getLegend().setEnabled(false);
        chart.setDescription("");
        chart.animateY(800, Easing.EasingOption.EaseInBounce);
        chart.setDrawHoleEnabled(false);
        chart.setTouchEnabled(true);
        chart.setDrawCenterText(false);
        chart.setDrawSliceText(true);
        chart.setOnChartValueSelectedListener(this);
        chart.invalidate(); // refresh

The pie chart is drawn and the x values are show as text.

I would like to replace the text in each pie slice to show a small image, depending on the x value.

I checked the docs and didn't find anything, is it possible to do this with this charting library ?

1

There are 1 best solutions below

0
On BEST ANSWER

No, that is not possible by default. However, it should not be too hard customize the library in a way to support that feature.

Just add a Bitmap to each entry in the PieChart and draw it on the location where the labels would usually be.