title: How to set Axis range in Java FX using SampleController?
body: <p>I have created an fxml layout using scene builder v2.0. I am modifying the chart in the controller file i.e, SampleController.java file. I was able to set the chart title using .setTitle method. I need to set the range of xAxis (Start, End, Ticks) and yAxis dynamically. In CSS it is easy to set using lowerBound and upperBound Property. But it is a permanent solution. Please provide your valuable suggestions and solutions.</p>
  
  <p><strong>Main.java:</strong></p>
  
  <pre><code>package application;
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Scene;
  import javafx.scene.control.SplitPane;
  import javafx.stage.Stage;
  public class Main extends Application{
      @Override
      public void start(Stage primaryStage) { 
          try {
              SplitPane root = (SplitPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
              Scene scene = new Scene(root,800,400);          
              scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
              primaryStage.setScene(scene);
              primaryStage.show();            
          } catch(Exception e) {
              e.printStackTrace();
          }
      }   
      public static void main(String[] args) {
          launch(args);
  
  
  
      }
  }
  </code></pre>
  
  <p>   </p>
  
  <p><strong>Sample.fxml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.chart.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.BorderPane?&gt;
  
  &lt;SplitPane dividerPositions="0.7892976588628763" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400.0" minWidth="800.0" prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SampleController"&gt;
    &lt;items&gt;
      &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"&gt;
           &lt;children&gt;
              &lt;LineChart fx:id="Ch" alternativeColumnFillVisible="true" layoutX="14.0" prefHeight="398.0" prefWidth="500.0"&gt;
                &lt;xAxis&gt;
                  &lt;NumberAxis side="BOTTOM" /&gt;
                &lt;/xAxis&gt;
                &lt;yAxis&gt;
                  &lt;NumberAxis layoutX="10.0" side="LEFT" /&gt;
                &lt;/yAxis&gt;
              &lt;/LineChart&gt;
           &lt;/children&gt;&lt;/AnchorPane&gt;
      &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"&gt;
           &lt;children&gt;
              &lt;Button fx:id="sine" layoutX="21.0" layoutY="101.0" mnemonicParsing="false" text="Sinusoidal" /&gt;
              &lt;Button fx:id="triangle" layoutX="21.0" layoutY="148.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="70.0" text="Triangle" /&gt;
              &lt;Button fx:id="square" layoutX="21.0" layoutY="187.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="70.0" text="Square" /&gt;
              &lt;Label layoutX="20.0" layoutY="40.0" prefHeight="17.0" prefWidth="83.0" text="Controls" /&gt;
           &lt;/children&gt;&lt;/AnchorPane&gt;
    &lt;/items&gt;
  &lt;/SplitPane&gt;
  </code></pre>
  
  <p><strong>SampleController.java</strong></p>
  
  <pre><code>package application;
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.animation.Animation;
  import javafx.animation.KeyFrame;
  import javafx.animation.Timeline;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.chart.Axis;
  import javafx.scene.chart.LineChart;
  import javafx.scene.chart.NumberAxis;
  import javafx.scene.chart.XYChart;
  import javafx.scene.chart.XYChart.Series;
  import javafx.scene.control.Button;
  import javafx.util.Duration;
  
  
  public class SampleController implements Initializable {
  
       final NumberAxis xAxis = new NumberAxis(0,24,3);
  
       final NumberAxis yAxis = new NumberAxis(0,1,0.1);
  
      @FXML //  fx:id="Ch"
      private LineChart&lt;Number, Number&gt; Ch= new LineChart&lt;&gt;(xAxis, yAxis); // No use of using a constructor.
      @FXML//  fx:id="sine"
      private Button sine; // Value injected by FXMLLoader
      @FXML//  fx:id="triangle"
      private Button triangle; // Value injected by FXMLLoader
      @FXML//  fx:id="Square"
      private Button square; // Value injected by FXMLLoader
  
  
  
  
      @Override // This method is called by the FXMLLoader when initialization is complete
      public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
          assert Ch != null : "fx:id=\"Ch\" was not injected: check your FXML file 'sample.fxml'.";
  
          // initialize your logic here: all @FXML variables will have been injected
          sine.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  System.out.println("Sinusoidal Signal Selected /n/n");
              }
          });
  
          triangle.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  System.out.println("Triangle Signal Selected /n/n");
              }
          });
  
          square.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  System.out.println("Square Signal Selected /n/n");
              }
          });
  
  
  
          //Ch = new LineChart&lt;&gt;(xAxis, yAxis); // This sadly loads a new chart but is not visible
  
          Ch.setTitle("PiScope Demo");
  
          //Need to set xAxis range Dynamically
  
          //Need to set yAxis range Dynamically
  
          /*
           * In CSS we can use lowerBound and upperBound Property.
           *          */     
  
      }
  }
  </code></pre>