JFreeChart XY-chart that refreshes with new set of

2019-04-15 19:12发布

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 how do I tell jfreechart to refresh the drawn graph and display it onthe canvas?

Thanks in advance,

Andreas

2条回答
Summer. ? 凉城
2楼-- · 2019-04-15 19:18

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.

查看更多
贼婆χ
3楼-- · 2019-04-15 19:20

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
}
查看更多
登录 后发表回答