Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...