So here\'s the deal, i\'m trying to code a GUI that shows live data on a linechart. So far so good, i can get the linechart working but not into the GUI.
Using scenebuil
Don't create new objects for @FXML injected members
Never use new
in conjunction with @FXML
, i.e., never write:
@FXML
private CategoryAxis xAxis = new CategoryAxis();
Instead, just write:
@FXML
private CategoryAxis xAxis;
The FXMLLoader
will automatically generate, i.e., create, a new object for each element in the FXML file and inject a reference to that into your controller where you provide an @FXML
annotation. So if you reset the @FXML
member reference to a new object you create in the controller there will be no association between that object and objects created by the loader.
Additionally, don't create another new LineChart within your initGraph() function. You already have a LineChart created by the FXMLLoader, just reference that. Same for NumberAxis and the other elements you are using @FXML injection with.
If you use an @FXML
annotation also use <fx:id>
You have:
@FXML
private CategoryAxis xAxis;
So in your fxml, you should define:
<xAxis fx:id="xAxis">
Otherwise, the FXMLLoader will not be able to inject a reference to the axis you defined in your FXML.
Aside
You may have other errors in your code (e.g., around concurrency and threading). So the above might not be all of your errors. In general, when creating an mcve, try to eliminate anything which is not relevant to the question at hand (e.g. the threading code and non-linechart portions of the FXML), but include everything that somebody could use to copy and paste your code to compile and run it to replicate your issue.
Note: The Ensemble sample application contains a sample program which updates a graph in real-time based upon audio spectrum input data.