为什么要将多个饼图合并为一个? MPAndroid图表

Why several Pie Charts are being merged into one? MPAndroidChart

我想在同一布局上显示 3 个饼图。我将不同的数据集插入到不同的图表中,但最后所有这些数据都显示在 1 个图表上,另外 2 个图表没有数据。 会不会是我无法在一个布局上创建多个图表的问题?

private PieChart firstCh, secondCh, thirdCh;
private void openDialog() {

    //code with dialog

        firstCh = dialogStat.findViewById(R.id.firstCharacter);
        secondCh = dialogStat.findViewById(R.id.secondCharacter);
        thirdCh = dialogStat.findViewById(R.id.thirdCharacter);

        ArrayList<PieEntry> statForFirst = new ArrayList<>();
        statForFirst.add(new PieEntry(myNumber, "Kiss"));
        statForFirst.add(new PieEntry(myNumber, "Marry"));
        statForFirst.add(new PieEntry(myNumber, "Kill"));

        ArrayList<PieEntry> statForSecond = new ArrayList<>();
        statForFirst.add(new PieEntry(myNumber, "Kiss"));
        statForFirst.add(new PieEntry(myNumber, "Marry"));
        statForFirst.add(new PieEntry(myNumber, "Kill"));

        ArrayList<PieEntry> statForThird = new ArrayList<>();
        statForFirst.add(new PieEntry(myNumber, "Kiss"));
        statForFirst.add(new PieEntry(myNumber, "Marry"));
        statForFirst.add(new PieEntry(myNumber, "Kill"));

        setNewChart(firstCh, statForFirst);
        setNewChart(secondCh, statForSecond);
        setNewChart(thirdCh, statForThird);

        //code with dialog
    }

private void setNewChart(PieChart chart, ArrayList<PieEntry> entries) {
        chart.getDescription().setEnabled(false);
        chart.getLegend().setEnabled(false);

        PieDataSet dataSet = new PieDataSet(entries, "");
        dataSet.setColors(getResources().getColor(R.color.pinkySarah), getResources().getColor(R.color.lightViola), getResources().getColor(R.color.eyeKiller));

        PieData data = new PieData(dataSet);
        data.setDrawValues(true);
        data.setValueFormatter(new PercentFormatter(chart));
        data.setValueTextSize(10f);
        data.setValueTextColor(R.color.darkViola);

        chart.setData(data);
    chart.invalidate();
    }

This is how it looks in my app 作为参考,我正在使用 LinearLayout

只是一个打字错误。

您已将所有数据添加到 statForFirst arraylist 而不是其他两个列表。解决这个问题就可以了