在 JFreeChart 中更新 PieChart
Update PieChart in JFreeChart
我使用 JFreeChart 创建了一个 PieChart。我终其一生都不知道如何在创建图表后对其进行更新。是创建全新图表的唯一方法吗?
如图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 these related examples, a component's Action
updates a Dataset
. In a MultiplePiePlot
, you can update the appearance of the pie chart view directly, as shown here.
附录:从PieChartDemo1
开始,重构数据集并添加合适的Action
,如下所示。
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。我终其一生都不知道如何在创建图表后对其进行更新。是创建全新图表的唯一方法吗?
如图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 these related examples, a component's Action
updates a Dataset
. In a MultiplePiePlot
, you can update the appearance of the pie chart view directly, as shown here.
附录:从PieChartDemo1
开始,重构数据集并添加合适的Action
,如下所示。
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);
}