title: How to draw three lines on dynamic JFreechart?
body: <p>I want to draw three lines for three values on time chart on xy-axis. from this helpful page <a href="https://stackoverflow.com/questions/11469865/making-dynamic-line-chart-using-jfree-chart-in-java">How to adjust the xand y axis line in jfreecharts</a> I can draw a one line for one value on time chart, so my question is that how can I draw three lines on time chart?</p>
  
  <p>Notice that drawing three line is reduced to drawing a two line, so if you can draw a two-line, then you're able to answer this question, I just want to find the key role here in this code that draws one line in order to add another line.</p>
  
  <p>In one way to do that I tried to put the following  <code>this.series.add(new Millisecond(), this.lastValue2);</code>on <code>actionPerformed()</code> and define a new <code>dataset</code> but this doesn't help. </p>
  
  <p>this is the code that is taken from previous link [<a href="https://stackoverflow.com/questions/11469865/making-dynamic-line-chart-using-jfree-chart-in-java">1</a>].</p>
  
  <pre><code>public class DynamicLineAndTimeSeriesChart extends ApplicationFrame implements ActionListener {
  
  /** The time series data. */
  private TimeSeries series;
  
  /** The most recent value added. */
  private double lastValue = 100.0;
  
  /** Timer to refresh graph after every 1/4th of a second */
  private Timer timer = new Timer((1000), this);//1/4th = 250 ms, to put 1 minute then = 1000*60. 1 second = 1000 ms, 1/4 secon = 250 ms
  private double lastValue2 = 1.0;
  /**
   * Constructs a new dynamic chart application.
   *
   * @param title  the frame title.
   */
  public DynamicLineAndTimeSeriesChart(final String title) {
  
      super(title);
      this.series = new TimeSeries("Random Data", Millisecond.class);
  
      final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
  
      final JFreeChart chart = createChart(dataset, dataset);
  
      timer.setInitialDelay(1000);
  
      //Sets background color of chart
      chart.setBackgroundPaint(Color.LIGHT_GRAY);
  
      //Created JPanel to show graph on screen
      final JPanel content = new JPanel(new BorderLayout());
  
      //Created Chartpanel for chart area
      final ChartPanel chartPanel = new ChartPanel(chart);
  
      //Added chartpanel to main panel
      content.add(chartPanel);
  
      //Sets the size of whole window (JPanel)
      chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
  
      //Puts the whole content on a Frame
      setContentPane(content);
  
      timer.start();
  
  }
  
  /**
   * Creates a sample chart.
   *
   * @param dataset  the dataset.
   *
   * @return A sample chart.
   */
  private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset2) 
  {
      final JFreeChart result = ChartFactory.createTimeSeriesChart("Dynamic Line And TimeSeries Chart",
          "Time (every 2 minutes)",
          "Value of binary bits",
          dataset,
          true,
          true,
          false
      );
  //        
  //        final JFreeChart result2 = ChartFactory.createTimeSeriesChart("Dynamic Line And TimeSeries Chart",
  //            "Time (every 2 minutes)",
  //            "Value of binary bits",
  //            dataset,
  //            true,
  //            true,
  //            false
   //        );
  //        
  
  
      final XYPlot plot = result.getXYPlot();
  //        final XYPlot plot2 = result2.getXYPlot();
  
  //        plot2.setBackgroundPaint(Color.BLACK);
  //        plot2.setDomainGridlinesVisible(true);
  //        
  
      plot.setBackgroundPaint(new Color(0xffffe0));
      plot.setDomainGridlinesVisible(true);
      plot.setDomainGridlinePaint(Color.lightGray);
      plot.setRangeGridlinesVisible(true);
      plot.setRangeGridlinePaint(Color.lightGray);
  
      ValueAxis xaxis = plot.getDomainAxis();
  
      xaxis.setAutoRange(true);
  
      //Domain axis would show data of 60 seconds for a time
      xaxis.setFixedAutoRange((1*60.0*1000.0));  // 60 seconds = 1 minutes, 60*60.0*1000.0= 1 hour of graph
      xaxis.setVerticalTickLabels(true);
  
      ValueAxis yaxis = plot.getRangeAxis();
      yaxis.setRange(0.0, 300.0);
  
  //        ValueAxis xaxis2 = plot2.getDomainAxis();
  
  //        xaxis2.setAutoRange(true);
  //
  //        //Domain axis would show data of 60 seconds for a time
  //        xaxis2.setFixedAutoRange((1*60.0*1000.0));  // 60 seconds = 1 minutes, 60*60.0*1000.0= 1 hour of graph
  //        xaxis2.setVerticalTickLabels(true);
  
      ValueAxis yaxis2 = plot.getRangeAxis();
      yaxis2.setRange(0.0, 1000.0);
  
      return result;
  }
  
  public void actionPerformed(final ActionEvent e) {
  
      final double factor = 0.9 + 0.2*Math.random();
      this.lastValue = this.lastValue * factor;
  
      this.lastValue2 = Math.random();
     // final Millisecond now = new Millisecond();
      this.series.add(new Millisecond(), this.lastValue);
  
     // System.out.println("Current Time in Milliseconds = " + now.toString()+", Current Value : "+this.lastValue);
  }
  }
  </code></pre>