How to update a chart in JFreeChart?

泄露秘密 提交于 2019-12-23 03:55:09

问题


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

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 ?


回答1:


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 here and here.




回答2:


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.

The chartPanel itself is added another JPanel, which in turn is placed in the main layout of the application.



来源:https://stackoverflow.com/questions/7149436/how-to-update-a-chart-in-jfreechart

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