1

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

Jon
  • 2,932
  • 2
  • 23
  • 30
Andreas Hornig
  • 2,439
  • 5
  • 28
  • 36

2 Answers2

1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • It's almost what I need, thanks! :) No I just have to understand everything, what it does and have to find out how to put it onto the WorldWindJava canvas. Perhaps you also have some ideas for achiving this? – Andreas Hornig May 14 '11 at 14:45
  • 1
    Sorry, I am unfamiliar with `WorldWindJava`, but I've found that `JFreeChart` is fairly easy to integrate; more above. – trashgod May 14 '11 at 16:53
  • Hi trashgod, I posted the code here http://stackoverflow.com/questions/5859286/2d-graph-animation-on-worldwindjava-canvas. Perhaps you know how I can update the chart regularly. Andreas – Andreas Hornig May 14 '11 at 23:09
  • 1
    I've reformatted your [code](http://stackoverflow.com/questions/5859286/2d-graph-animation-on-worldwindjava-canvas) and added links in a comment. I've not answered hoping that a `WorldWindJava` user will respond. As noted in the [faq](http://stackoverflow.com/faq), editing your question (say by adding links) may prove fruitful. – trashgod May 14 '11 at 23:32
1

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
}
Jon
  • 2,932
  • 2
  • 23
  • 30