Java 从JFreeChart中删除一个饼图分区标签

Java 从JFreeChart中删除一个饼图分区标签,java,charts,jfreechart,Java,Charts,Jfreechart,如何从JFreeChart饼图中删除一个标签,但保留其余标签 这是我的饼图的简化版本。我想要所有饼图切片的标签,除了“休眠”类别。它更像是一个占位符 DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Cat1", 2); dataset.setValue("Cat2", 4); dataset.setValue("Cat3", 3); dataset.setValue("d

如何从JFreeChart饼图中删除一个标签,但保留其余标签

这是我的饼图的简化版本。我想要所有饼图切片的标签,除了“休眠”类别。它更像是一个占位符

DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Cat1", 2);
    dataset.setValue("Cat2", 4);
    dataset.setValue("Cat3", 3);
    dataset.setValue("dormant", 2);

JFreeChart chart = ChartFactory.createPieChart3D(
    null,
    dataset,
    false, // legend?
    true, // tooltips?
    false // URLs?
    );

PiePlot3D plot = (PiePlot3D) chart.getPlot();

//CREATE LABELS, but I don't want any for the "dormant" category
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( "{0} ({2})", new DecimalFormat("0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(labelGen);

如果标签生成器为标签返回null,则饼图不会显示该部分的标签。因此,您可以实现如下结果:

    StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
            "{0} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")) {

        @Override
        public String generateSectionLabel(PieDataset dataset, Comparable key) {
            if (key.equals("dormant")) {
                return null;
            }
            return super.generateSectionLabel(dataset, key);
        }

    };

谢谢我想我必须用StandardPieSectionLabelGenerator覆盖一些东西,我担心它可能会很粗糙。很高兴这么简单!