In the code below I am conducting an experiment for which I need to plot almost 10 graphs per second ( time interval 100) for total of 50. However when I decrease the time inter
You're updating the model from Thread thread
. To update on the EDT, use a javax.swing.Timer
, as shown here, or SwingWorker
, as shown here.
Addendum: To verify the hypothesis, I added the following javax.swing.Timer
to init()
.
Timer t = new Timer(200, new ActionListener() {
int k = 0;
@Override
public void actionPerformed(ActionEvent e) {
if (k++ < 19) {
final double[] x = new double[1000];
final double[] y = new double[1000];
for (int i = 0; i < y.length; i++) {
x[i] = i;
y[i] = i * i * k;
}
plot2d(k % 12, x, y, "plot#" + k);
}
}
});
t.start();
I also used invokeLater()
in main()
.
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
FastChart demo = new FastChart("X Y Plot");
}
});