title: Dual JFreeChart not running; only one running
body: <p>Please let me know how I can make a program for <code>JFreeChart</code> in a <code>JFrame</code>. There are two <code>JFreeCharts</code> and both are visible, but only one is running; the other is still, why it is happening? Is there any sequential mistake in my code or what?</p>
  <p>If you explain or give any hint, I shall be thankful to you.</p>
  <p>Please read carefully and you can run on your laptop/PC, it is running code.</p>
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.EventQueue;
  import java.awt.FlowLayout;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.Random;
  import javax.swing.JButton;
  import javax.swing.JComboBox;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  import org.jfree.chart.ChartFactory;
  import org.jfree.chart.ChartPanel;
  import org.jfree.chart.JFreeChart;
  import org.jfree.chart.axis.ValueAxis;
  import org.jfree.chart.plot.XYPlot;
  import org.jfree.data.time.DynamicTimeSeriesCollection;
  import org.jfree.data.time.Second;
  import org.jfree.data.xy.XYDataset;
  import org.jfree.ui.ApplicationFrame;
  
  /**
   * @see http://stackoverflow.com/a/15521956/230513
   * @see http://stackoverflow.com/questions/5048852
   */
  public class Grid_Layout extends ApplicationFrame {
  
      private static final long serialVersionUID = 1L;
      private static final String TITLE1 = &quot;X-Axis&quot;;
      private static final String TITLE2 = &quot;Y-Axis&quot;;
      private static final String TITLE3 = &quot;Z-Axis&quot;;
      private static final String START = &quot;Start&quot;;
      private static final String STOP = &quot;Stop&quot;;
      private static final float MINMAX = 100;
      private static final int COUNT = 2 * 60;
      private static final int FAST = 100;
      private static final int SLOW = FAST * 5;
      private static final Random random = new Random();
      private static final Random random2 = new Random();
      private Timer timer;
      private Timer timer2;
  
      public Grid_Layout(final String title) {
          super(title);
          
          final XYDataset dataset = createDataset1();
          JFreeChart chart = createChart(dataset);
  
          final XYDataset dataset2 = createDataset2();
          JFreeChart chart2 = createChart2(dataset2);
          
  
          final JButton run = new JButton(STOP);
          run.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  String cmd = e.getActionCommand();
                  if (STOP.equals(cmd)) {
                      timer.stop();
                      run.setText(START);
                  } else {
                      timer.start();
                      run.setText(STOP);
                  }
              }
          });
  
          final JComboBox&lt;String&gt; combo = new JComboBox&lt;String&gt;();
          combo.addItem(&quot;Fast&quot;);
          combo.addItem(&quot;Slow&quot;);
          combo.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  if (&quot;Fast&quot;.equals(combo.getSelectedItem())) {
                      timer.setDelay(FAST);
                  } else {
                      timer.setDelay(SLOW);
                  }
              }
          });
  
          this.add(new ChartPanel(chart) {
              private static final long serialVersionUID = 1L;
  
              @Override
              public Dimension getPreferredSize() {
                  return new Dimension(640, 480);
              }
          }, BorderLayout.CENTER);
  
          this.add(new ChartPanel(chart2) {
              private static final long serialVersionUID = 1L;
  
              @Override
              public Dimension getPreferredSize() {
                  return new Dimension(640, 480);
              }
          }, BorderLayout.CENTER);
  
          JPanel btnPanel = new JPanel(new FlowLayout());
          btnPanel.add(run);
          btnPanel.add(combo);
          this.add(btnPanel);
      }
  
      private float randomValue() {
          return (float) (random.nextGaussian() * MINMAX / 3);
      }
  
      private float[] gaussianData() {
          float[] a = new float[COUNT];
          for (int i = 0; i &lt; a.length; i++) {
              a[i] = randomValue();
          }
          return a;
      }
  
      private JFreeChart createChart(final XYDataset dataset) {
          final JFreeChart result = ChartFactory.createTimeSeriesChart(TITLE1, &quot;Time (seconds)&quot;, &quot;Intensity (cm/s)&quot;,
                  dataset, true, true, false);
  
          final XYPlot plot = result.getXYPlot();
          ValueAxis domain = plot.getDomainAxis();
          domain.setAutoRange(true);
  
          ValueAxis range = plot.getRangeAxis();
          range.setRange(-MINMAX, MINMAX);
          range.setAutoRange(true);
          return result;
      }
  
      private JFreeChart createChart2(final XYDataset dataset) {
          final JFreeChart result = ChartFactory.createTimeSeriesChart(TITLE2, &quot;Time (seconds)&quot;, &quot;Intensity (cm/s)&quot;,
                  dataset, true, true, false);
  
          final XYPlot plot = result.getXYPlot();
          ValueAxis domain = plot.getDomainAxis();
          domain.setAutoRange(true);
  
          ValueAxis range = plot.getRangeAxis();
          range.setRange(-MINMAX, MINMAX);
          range.setAutoRange(true);
          return result;
      }
  
      public void start() {
          timer.start();
      }
  
      private XYDataset createDataset1() {
          final DynamicTimeSeriesCollection dataset = new DynamicTimeSeriesCollection(1, COUNT, new Second());
          dataset.setTimeBase(new Second(0, 0, 0, 24, 5, 2022));
          dataset.addSeries(gaussianData(), 0, &quot;X&quot;);
          timer = new Timer(FAST, new ActionListener() {
              float[] newData = new float[1];
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  newData[0] = randomValue();
                  dataset.advanceTime();
                  dataset.appendData(newData);
              }
          });
          return dataset;
      }
  
      private XYDataset createDataset2() {
          final DynamicTimeSeriesCollection dataset = new DynamicTimeSeriesCollection(1, COUNT, new Second());
          dataset.setTimeBase(new Second(0, 0, 0, 26, 5, 2022));
          dataset.addSeries(gaussianData(), 0, &quot;Y&quot;);
          timer2 = new Timer(FAST, new ActionListener() {
              float[] newData2 = new float[1];
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  newData2[0] = randomValue();
                  dataset.advanceTime();
                  dataset.appendData(newData2);
              }
          });
          return dataset;
      }
  
      public static void main(final String[] args) {
          EventQueue.invokeLater(new Runnable() {
              @Override
              public void run() {
                  Grid_Layout demo = new Grid_Layout(&quot;Vibration Analyser&quot;);
                  demo.setLayout(new GridLayout(3, 1));
                  demo.pack();
                  demo.setLocationRelativeTo(null);
                  demo.setVisible(true);
                  demo.start();
              }
          });
      }
  }
  </code></pre>