安卓图表库MPAndroidChart如何移除图例?

12

我正在使用MPAndroidChart库,我想要移除饼图顶部右侧的数值,应该如何操作?

4个回答

29

您所提到的值属于图例

要禁用它们(防止它们被显示),请调用

Legend l = chart.getLegend();
l.setEnabled(false);

1
在新版本中,你应该使用 chart.setDrawLegend(false); - Filipe Ramos
1
这是旧版本的发布 :-) - Philipp Jahoda
1
如何隐藏特定的图例,比如数据集3的图例? - Nouman Ch

1
你可以像这样设置。
linechart.setData();
...
linechert.getLegend().setEnable(false);

"Gone Legend 应该在 setData() 的后面。"

0

尝试 pieChart.setDrawSliceText(false)


不,这将从饼图内部删除x值,但我们在饼图右上角有一个x值列表,在此列表下面我们有饼图标签,我想删除此列表和标签。 - Russell Ghana

0
将以下代码添加到xml文件中:

<com.github.mikephil.charting.charts.PieChart
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pie_chart">
</com.github.mikephil.charting.charts.PieChart>

将以下内容写入 .java 文件中:

pieChart = findViewById(R.id.pie_chart);
     
Legend l = pieChart.getLegend();
l.setEnabled(false);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接