【发布时间】:2019-05-21 20:33:59
【问题描述】:
JFreeChart 没有像我预期的那样更新。
我有下面的代码。有 2 个面板,一个带有增量按钮,一个带有显示数据的图表。
每按一次+1按钮,就应该更新数据;但图表未显示新数据。
非常感谢您的任何帮助。
public class GUItest3 extends JFrame {
private JPanel evoTabbedPanel, outputPanel;
float tempCtr;
public GUItest3(){
tempCtr = 0;
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
JButton incrementorButton = new JButton ("+1");
incrementorButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tempCtr++;}
});
toolBar.add(incrementorButton);
evoTabbedPanel = new JPanel();
evoTabbedPanel.add(toolBar);
MyGraphPanel myGraphPanel = new MyGraphPanel();
outputPanel = new JPanel();
outputPanel.setLayout(new GridBagLayout());
outputPanel.add(myGraphPanel);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Generations", evoTabbedPanel);
tabbedPane.addTab("Output", outputPanel);
getContentPane().add(tabbedPane);
pack();
setVisible(true);
}
class MyGraphPanel extends JPanel {
JFreeChart myChart;
ChartPanel chartPanel;
XYSeriesCollection myDataset;
private MyGraphPanel(){
XYSeries myData = new XYSeries( "My data" );
myData.add(1.0, 1.0);
myData.add(2.0, tempCtr);
myDataset = new XYSeriesCollection();
myDataset.addSeries(myData);
myChart = ChartFactory.createXYLineChart("My chart", "X axis", "Y axis",
myDataset, PlotOrientation.VERTICAL, true, true, false);
chartPanel = new ChartPanel(myChart);
this.add(chartPanel);
}
}
}
【问题讨论】:
标签: java jfreechart