Update PieChart in JFreeChart

十年热恋 提交于 2019-11-28 02:20:46
trashgod

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!