开发者

JFreeChart XY-chart that refreshes with new set of data? Example?

I want to learn how to learn how to create some charts with jfreechart and googlefor some examples. but I couldn't find what I need. This here is good http://www.java2s.com/Code/Java/Chart/CatalogChart.htm but doesn't have a refreshing graph with new displayed values.

I would like to redraw a chart every nth seconds because I update an external dile witha set of values I want to display here. So 开发者_StackOverflowhow do I tell jfreechart to refresh the drawn graph and display it onthe canvas?

Thanks in advance,

Andreas


This example features a chart that is updated at a selectable rate using an instance of javax.swing.Timer.

Addendum: JFreeChart follows the Swing separable-model variation of MVC. ChartPanel is a convenient top-level view, as seen in this example. For secular data, a TimeSeriesCollection of TimeSeries makes a straightforward data model.


I had the same issue, this worked for me:

private void refreshChart(){
    jPanel_GraphicsTop.removeAll();
    jPanel_GraphicsTop.revalidate(); // This removes the old chart aChart = createChart();
    aChart.removeLegend();
    ChartPanel chartPanel = new ChartPanel(aChart);
    jPanel_GraphicsTop.setLayout(new BorderLayout());
    jPanel_GraphicsTop.add(chartPanel);
    jPanel_GraphicsTop.repaint(); // This method makes the new chart appear
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜