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;
    }

如何打开标签?

最佳答案

您需要使用setLabelGenerator()上的PiePlot方法将标签生成器设置为null。您可以从图表中获取图并将其转换为PiePlot:

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

08-15 17:54