title: Display chart in JavaFX
body: <p>I tried to rewrite and simplify the oracle tutorial for charts so, that you have a controller class and you work with fxml.
  For some reason it is not working.</p>
  
  <p>Here is my code:
  Main class:</p>
  
  <pre><code>public class BarChartSample extends Application {
  
      Stage primaryStage;
  
      public void start(Stage primaryStage) {
          this.primaryStage = primaryStage;
          primaryStage.setTitle("Bar Chart Sample");
  
          showPage();
      }
  
      public void showPage(){
          try {
              FXMLLoader loader = new FXMLLoader();
          loader.setLocation(BarChartSample.class.getResource("ChartPage.fxml"));
              AnchorPane pane = loader.load();
  
              Scene scene  = new Scene(pane);
              primaryStage.setScene(scene);
              primaryStage.show();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class Controller {
      final static String performance = "Performance:";
  
      @FXML
      NumberAxis xAxis = new NumberAxis();
      @FXML
      CategoryAxis yAxis = new CategoryAxis();
  
      @FXML
      BarChart&lt;Number,String&gt; bc;
  
      public void initialize(){
          xAxis.setLabel("Percent");  
          xAxis.setTickLabelRotation(90);
          yAxis.setLabel("Performance");
  
          bc = new BarChart&lt;Number,String&gt;(xAxis,yAxis);
  
          XYChart.Series series1 = new XYChart.Series();     
          series1.getData().add(new XYChart.Data(80, performance));
          bc.getData().add(series1);
      }
  }
  </code></pre>
  
  <p>FXML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.chart.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;AnchorPane prefHeight="393.0" prefWidth="419.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller"&gt;
     &lt;children&gt;
        &lt;BarChart fx:id="bc" layoutX="-40.0" layoutY="-3.0" prefHeight="205.0" prefWidth="409.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0"&gt;
          &lt;xAxis&gt;
            &lt;CategoryAxis fx:id="yAxis" side="BOTTOM" /&gt;
          &lt;/xAxis&gt;
          &lt;yAxis&gt;
            &lt;NumberAxis side="LEFT" fx:id="xAxis" /&gt;
          &lt;/yAxis&gt;
        &lt;/BarChart&gt;
       &lt;TextArea layoutX="103.0" layoutY="14.0" maxHeight="100.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.leftAnchor="21.0"AnchorPane.rightAnchor="21.0" AnchorPane.topAnchor="5.0" /&gt;
          &lt;/children&gt;
        &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>It won't display the chart properly, it is just drawing a few lines. Why? Thank you!</p>