在JFreeChart中更新PieChart [英] Update PieChart in JFreeChart

查看:87
本文介绍了在JFreeChart中更新PieChart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用JFreeChart创建了一个PieChart.我一辈子都无法弄清楚图表创建后如何更新.这样做是创建全新图表的唯一方法吗?

I have created a PieChart using JFreeChart. I for the life of my cant figure out how to update the chart once it has been created. Is the only way to do that to create an entirely new chart?

推荐答案

此处所示,您可以更改图表渲染后.在这种情况下,更新图表的数据 PieDataset,然后将监听 view ;在此相关的示例中,按钮的Action更新了CategoryDataset.在MultiplePiePlot中,您可以直接更新饼图视图的外观,如在此处显示.

As shown here, you can alter a chart after it's been rendered. In this case, update the chart's data model, PieDataset, and the listening view will follow; in this related example a button's Action updates a CategoryDataset. In a MultiplePiePlot, you can update the appearance of the pie chart view directly, as shown here.

附录:从 PieChartDemo1 ,重构数据集并添加一个合适的Action,如下所示.

Addendum: Starting from PieChartDemo1, re-factor the dataset and add a suitable Action, as shown below.

private static final DefaultPieDataset dataset = createDataset();
…
public PieChartDemo1(String title) {
    super(title);
    add(createDemoPanel());
    add(new JButton(new AbstractAction("Update") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dataset.setValue("Apple", dataset.getValue("Apple").doubleValue() + 1);
        }
    }), BorderLayout.SOUTH);
}

这篇关于在JFreeChart中更新PieChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆