A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
radradish
- Posts: 1
- Joined: Sun Jan 18, 2009 6:02 pm
Post
by radradish » Sun Jan 18, 2009 6:13 pm
Hello
I'm trying to add some random data to series (XYseries) and update a chart every desired amount of time from within a thread. Here is my code:
Code: Select all
Runnable plotUpdater = new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
//add some random data without fireing a redraw signal
series1.add((double)i, (double)(Math.abs(rand.nextInt()) % 20), false);
}
//fire a signal to redraw
series1.fireSeriesChanged();
}
};
public class MyThread extends Thread {
public void run() {
while (!S) {
SwingUtilities.invokeLater(plotUpdater);
try {
this.sleep(waitms);
} catch (InterruptedException ex) {
Logger.getLogger(RRAsepView.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("interrupted!");
}
}
}
}
The invokeLater or invokeAndWait methods don't work. The plot gets updated *sometimes* just after the first run of 'while' loop.
What's the proper way of fireing the fireSeriesChanged signal from within an object of class extending java.lang.Thread?
Kind regards
Rad Radish
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Jan 20, 2009 10:38 am
I don't see anything obviously wrong, except perhaps that each call to the updater is going to update the same x-values (0 to 99). If possible, try to put together a small self-contained demo that I can copy, paste and run...then I can see if the problem is reproduced on my setup.
-
Taqua
- JFreeReport Project Leader
- Posts: 698
- Joined: Fri Mar 14, 2003 3:34 pm
-
Contact:
Post
by Taqua » Tue Jan 20, 2009 1:56 pm
Also note that a repaint-request is not immediately honored by the AWT. If more than one repaint sits in the queue, then only the last one will be honored. So if your system is under stress or fires redraw events faster than the AWT handles them, you will see some dropped requests and definitely no smooth animation.