Android MP Pie Chart 如何从饼图中删除文本和值

Eru*_*rum 6 android pie-chart mpandroidchart

实际图像

我如何使用MPAndroidChart实现这一目标

使用版本:com.github.PhilJay:MPAndroidChart:v3.1.0-alpha 为图例和饼图边距添加代码:

private void setPieChartData() {
        ///sf/answers/3538604191/
        pieChart.setUsePercentValues(true);
        pieChart.getDescription().setEnabled(false);
        pieChart.setExtraOffsets(5,5,10,5);
        pieChart.setDragDecelerationFrictionCoef(0.9f);
        pieChart.setDrawCenterText(false);
        pieChart.setDrawHoleEnabled(false);
        //pieChart.animateY(1000, Easing.EasingOption.EaseInOutCubic);
        ArrayList<PieEntry> yValues = new ArrayList<>();
        yValues.add(new PieEntry(34f,"Ilala"));
        yValues.add(new PieEntry(56f,"Temeke"));
        yValues.add(new PieEntry(66f,"Kinondoni"));
        yValues.add(new PieEntry(45f,"Kigamboni"));
        yValues.add(new PieEntry(45f,"Kigamboni2"));
        pieChart.setDrawEntryLabels(false);

        PieDataSet dataSet = new PieDataSet(yValues, "Desease Per Regions");
        dataSet.setSliceSpace(0.1f);
        dataSet.setDrawValues(false);
        dataSet.setSelectionShift(5f);
        dataSet.setColors(ColorTemplate.VORDIPLOM_COLORS);

        PieData pieData = new PieData((dataSet));
        pieData.setValueTextSize(10f);
        pieData.setValueTextColor(Color.BLACK);
        pieChart.setData(pieData);
        pieChart.setDrawSliceText(false);
        setLegend();
    }

    private void setLegend() {
        Legend l = pieChart.getLegend();
        l.setFormSize(10f); // set the size of the legend forms/shapes
        l.setForm(Legend.LegendForm.SQUARE); // set what type of form/shape should be used
        l.setYOffset(5f);
        //l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); // set vertical alignment for legend
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); // set horizontal alignment for legend
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setTextSize(12f);
        l.setTextColor(Color.BLACK);
        //l.setXEntrySpace(5f); // set the space between the legend entries on the x-axis
        l.setYEntrySpace(1f); // set the space between the legend entries on the y-axis
        // set custom labels and colors
        List<LegendEntry> entries = new ArrayList<>();
        ArrayList<PieEntry> yValues = new ArrayList<>();
        yValues.add(new PieEntry(34f,"Ilala"));
        yValues.add(new PieEntry(56f,"Temeke"));
        yValues.add(new PieEntry(66f,"Kinondoni"));
        yValues.add(new PieEntry(45f,"Kigamboni"));
        yValues.add(new PieEntry(45f,"Kigamboni2"));
        for (int i = 0; i < 3; i++) {
            LegendEntry entry = new LegendEntry();
            entry.formColor = ColorTemplate.VORDIPLOM_COLORS[i];
            entry.label = yValues.get(i).getLabel() ;
            entries.add(entry);
        }
        l.setCustom(entries);
    }
   [![code result][2]][2]
Run Code Online (Sandbox Code Playgroud)

如何设置图例的位置与实际图像相同我在设置其布局时遇到问题。更正代码并分享任何链接以获取帮助请分享详细信息以解决此问题

代码结果

如何解决此 UI 问题..图例标签应位于与所需模拟相同的右侧 在此处输入图片说明

Jee*_*ede 9

删除条目值和标签使用方法:

myPieChart.setDrawSliceText(false); // To remove slice text
myPieChart.setDrawMarkers(false); // To remove markers when click
myPieChart.setDrawEntryLabels(false); // To remove labels from piece of pie
myPieChart.getDescription().setEnabled(false); // To remove description of pie
Run Code Online (Sandbox Code Playgroud)

要在图表旁边显示图例,请尝试以下方法:

Legend l = myPieChart.getLegend(); // get legend of pie
l.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER); // set vertical alignment for legend
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); // set horizontal alignment for legend
l.setOrientation(Legend.LegendOrientation.VERTICAL); // set orientation for legend
l.setDrawInside(false); // set if legend should be drawn inside or not
Run Code Online (Sandbox Code Playgroud)

这里MPAndroidChart 的主文档页面查看更多信息


小智 5

我希望它会有所帮助!

我做到了,

    pieChart.setDrawCenterText(true);
    pieChart.setDrawEntryLabels(true);
    pieChart.setDrawMarkers(false);
    pieChart.getDescription().setEnabled(false);

    pieChart.getLegend().setEnabled(false);
Run Code Online (Sandbox Code Playgroud)

只需更改为 false all,您就不会看到任何文本![抱歉,如果我的英语不好]