在MPAndroidChart饼图中显示图像而不是文本 [英] Show image instead of text in MPAndroidChart pie chart

查看:332
本文介绍了在MPAndroidChart饼图中显示图像而不是文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用MPAndroidChart绘制的android应用程序中有一个饼图.

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

绘制饼图,x值显示为文本.

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

我想替换每个饼图中的文本以显示一个小的图像,具体取决于x值.

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 ?

推荐答案

否,默认情况下不可能.但是,以支持该功能的方式自定义库应该不会太困难.

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

只需在PieChart中的每个条目上添加一个Bitmap,然后将其绘制在标签通常所在的位置即可.

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

这篇关于在MPAndroidChart饼图中显示图像而不是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆