title: JavaFX Adding multiple XYChart.Series to LineChart without explicating declaring each series
body: <p>I have been going through the following tutorial for creating JavaFX graphs
  <a href="https://docs.oracle.com/javafx/2/charts/line-chart.htm" rel="nofollow">https://docs.oracle.com/javafx/2/charts/line-chart.htm</a></p>
  
  <p>My question is, how can I dynamically create and add new series of data to my LineChart without explicating declaring each series i.e. series1, series2?</p>
  
  <p>When I compile and run my program only a single series has been added. </p>
  
  <p>Here is my code</p>
  
  <p><strong>Main class that creates the LineChart and instantiate 10 different companies.</strong> </p>
  
  <pre><code>    public class StockChart extends Application {
  
      @Override public void start(Stage stage) {
  
          stage.setTitle("Stock Market");
          final CategoryAxis xAxis = new CategoryAxis();
          final NumberAxis yAxis = new NumberAxis();
           xAxis.setLabel("Time of Day");
           yAxis.setLabel("Price Per Stock");
           LineChart&lt;String,Number&gt; lineChart = 
                  new LineChart&lt;String,Number&gt;(xAxis,yAxis);
          Scene scene  = new Scene(lineChart,800,600); 
          lineChart.setTitle("Stock Exchange");
  
          String[] timeOfDay = {"8:00AM", "9:00AM", "10:00AM", "161:00AM", "12:00PM",
                                "1:00PM", "2:00PM", "3:00PM", "4:00PM" };
          String[] stockCompany = { "AAPL", "ORCL", "MSFT", "GOOG", "AMZN", "FB", "HPQ", "YHOO", "ADSK", "ATVI"};
  
          for(int i = 0; i &lt; stockCompany.length; i++) {
            CompanyStockData tmpCompany = new CompanyStockData(lineChart, timeOfDay, stockCompany[i]);
            lineChart.getData().add(tmpCompany.generateStock());
            // lineChart.getData().add(line.generateStock());
            // lineChart.seriesRemoved(line.series);
          }
  
  
  
          stage.setScene(scene);
          stage.show();
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
    }
  </code></pre>
  
  <p><strong>CompanyStockData Class for generating a new series to be added to LineChart</strong></p>
  
  <pre><code>public class CompanyStockData extends StockChart {
    protected   LineChart&lt;String,Number&gt; lineChart;
    protected   String[] timeOfDay;
    protected  String companyName;
    public  XYChart.Series series = new XYChart.Series();
  
    public CompanyStockData(LineChart&lt;String,Number&gt; lineChart, String[] timeOfDay, String companyName) {
      this.lineChart = lineChart;
      this.timeOfDay = timeOfDay;
      this.companyName = companyName;
    }
  
    public XYChart.Series generateStock() {
      series.setName(companyName);
      System.out.println(lineChart);
      for(int i = 0; i &lt; timeOfDay.length; i++) {
        System.out.println(timeOfDay[i]);
        series.getData().add(new XYChart.Data(timeOfDay[i], i*2));
      }
      return series;
    }
  
    public static void main(String[] args) {
  
    }
  
    @Override
    public String toString() {
      return "Company : " + this.companyName +
              " Time Of Day Length " + this.timeOfDay.length;
    }
  
  }
  </code></pre>