Timing issue with plotting multiple graphs fast

后端 未结 1 865
天命终不由人
天命终不由人 2021-01-25 06:29

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

相关标签:
1条回答
  • 2021-01-25 06:54

    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");
        }
    });
    

    image

    0 讨论(0)
提交回复
热议问题