title: JavaFX How can I make a line chart out of an observable list?
body: <p>I have been playing around with the line chart tutorial here: <a href="http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/line-chart.htm#CIHGBCFI" rel="nofollow noreferrer">http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/line-chart.htm#CIHGBCFI</a></p>
  
  <p>I want to extend the tutorial and attempt to build a line chart out of data from a database, instead of setting data like this:</p>
  
  <pre><code>series.getData().add(new XYChart.Data(1, 23));
  series.getData().add(new XYChart.Data(2, 14));
  </code></pre>
  
  <p>What I have to import data from database:</p>
  
  <pre><code>public ObservableList&lt;Items&gt; loadChart() {
      try {
          Statement stmt = connection.createStatement();
          ResultSet rs = stmt.executeQuery("SELECT cost, date FROM Items ORDER BY date ASC");
  
          ObservableList&lt;Items&gt; data = FXCollections.observableArrayList();
  
          while(rs.next()){
              Items items = new Items();
              items.setCost(rs.getInt(1));
              items.setDate(rs.getString(2));
              data.add(items);
  
          }
  
          return data;
  
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>I want to plot cost and date against in a line chart... Yet don't know how to do so (based on observable list and the tutorial).</p>