title: JavaFX plot a chart: how to assign values in a class
body: <p>I was trying to create a class which can plot xy charts by modifying the example in <a href="http://docs.oracle.com/javafx/2/charts/line-chart.htm" rel="nofollow">http://docs.oracle.com/javafx/2/charts/line-chart.htm</a>. The codes are provided below. How can I change the data and title? If I set lineChart.setTitle(title); as lineChart.setTitle("abc"); it will work, but when I use a variable name. It doesn't. </p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.chart.LineChart;
  import javafx.scene.chart.NumberAxis;
  import javafx.scene.chart.XYChart;
  import javafx.stage.Stage;
  
  import java.util.ArrayList;
  
  public class PlotLines extends Application {
  private String title;
  private String xLab;
  private String yLab;
  double [][] xy;
  
  public void setTitle(String title) {
      this.title = title;
  }
  
  public void setxLab(String xLab) {
      this.xLab = xLab;
  }
  
  public void setyLab(String yLab) {
      this.yLab = yLab;
  }
  
  public void setxy(double[][] xy) {
      this.xy = xy;
  }
  
  public void plot(){
      launch();
  }
  
  
  @Override
  public void start(Stage stage) throws Exception {
      //stage.setTitle(title);
      //defining the axes
      final NumberAxis xAxis = new NumberAxis();
      final NumberAxis yAxis = new NumberAxis();
      xAxis.setLabel(xLab);
      yAxis.setLabel(yLab);
  
      //creating the chart
      final LineChart&lt;Number,Number&gt; lineChart =
              new LineChart&lt;Number,Number&gt;(xAxis,yAxis);
  
      lineChart.setTitle(title);
      //defining a series
      XYChart.Series series = new XYChart.Series();
      series.setName("Data Points");
      //populating the series with data
  
      //System.out.println(xy.length);
  
      series.getData().add(new XYChart.Data(1, 23));
      series.getData().add(new XYChart.Data(2, 14));
      series.getData().add(new XYChart.Data(3, 15));
      series.getData().add(new XYChart.Data(4, 24));
      series.getData().add(new XYChart.Data(5, 34));
      series.getData().add(new XYChart.Data(6, 36));
      series.getData().add(new XYChart.Data(7.5, 22));
      series.getData().add(new XYChart.Data(8, 45));
      series.getData().add(new XYChart.Data(9, 43));
      series.getData().add(new XYChart.Data(10, 17));
  
      series.getData().add(new XYChart.Data(11, 29));
      series.getData().add(new XYChart.Data(12, 25));
  
      Scene scene  = new Scene(lineChart,800,600);
      lineChart.getData().add(series);
  
      stage.setScene(scene);
      stage.show();
  }
  }
  </code></pre>
  
  <p>The following codes are to call this this class</p>
  
  <pre><code>public class PlotExample  {
  
  
  
  public static void main(String[] args) {
  
      double [][] xy = {{1.,2.},{3.,5.},{6.,7.}};
  
      PlotLines aa = new PlotLines();
      aa.setTitle("CGM");
      aa.setxLab("Time");
      aa.setyLab("Glucose");
      aa.setxy(xy);
  
      aa.plot();
  }
  }
  </code></pre>