java 如何更新 JFreeChart 中的图表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7149436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update a chart in JFreeChart?
提问by sam
I have a combinedXYPlot and a drop-down list. I want to update my chart based on user input from drop-down. How to do this? I tried the following code
我有一个组合 XYPlot 和一个下拉列表。我想根据下拉菜单中的用户输入更新我的图表。这个怎么做?我尝试了以下代码
frmJPanel.getContentPane().removeAll();
frmJPanel.setLayout(new BorderLayout());
initChart(option);
frmJPanel.repaint();
The changes are reflected only after I minimize/ maximize the window. What is the function that needs to be called? What is the better way to do this ?
只有在最小化/最大化窗口后才会反映更改。需要调用的函数是什么?什么是更好的方法来做到这一点?
采纳答案by trashgod
ChartPanel
"registers with the chart to receive notification of changes to any component of the chart. The chart is redrawn automatically whenever this notification is received." There are examples hereand here.
ChartPanel
“注册图表以接收图表任何组件更改的通知。每当收到此通知时,图表将自动重绘。” 这里和这里有例子。
回答by Joachim H. Skeie
I have my chart inside a org.jfree.chart.ChartPanel. When I want to update the chart I simply call on the chartPanel.repaint() method.
我在 org.jfree.chart.ChartPanel 中有我的图表。当我想更新图表时,我只需调用 chartPanel.repaint() 方法。
The chartPanel itself is added another JPanel, which in turn is placed in the main layout of the application.
chartPanel 本身添加了另一个 JPanel,它依次放置在应用程序的主布局中。