Show image instead of text in MPAndroidChart pie chart

为君一笑 提交于 2019-12-14 04:01:00

问题


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:


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.



来源:https://stackoverflow.com/questions/30962622/show-image-instead-of-text-in-mpandroidchart-pie-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!