简体   繁体   English

从 JFreeChart 饼图中删除标签

[英]Remove labels from JFreeChart Pie Chart

public static JFreeChart createChart(String title, List <Result> results){

    DefaultPieDataset pieDataset = new DefaultPieDataset();

    Iterator<Result> itr = results.iterator();

    while (itr.hasNext()) {
        Result result = itr.next();
        String itemName = result.getItemName();
        BigDecimal itemResult = result.getItemResult();
        pieDataset.setValue(itemName, itemResult);
        }

        JFreeChart chart = null;

        try {
            chart = ChartFactory.createPieChart(title, pieDataset,true, false, false);

        } catch (Exception e) {
            log.error("Threw a ParseException in createChart:, full message:",
                    e);
        }

    return chart;
    }    

How do I turn the labels of?我如何打开标签?

You will need to set the label generator to null, using the setLabelGenerator() method on PiePlot .您需要使用 PiePlot 上的setLabelGenerator()方法将 label 生成器设置为PiePlot You can get the plot from the chart and cast it to a PiePlot :您可以从图表中获取 plot 并将其转换为PiePlot

((PiePlot) chart.getPlot()).setLabelGenerator(null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM