I am looking for a way to put 3 LineCharts
into single window. I mean I want to have them next to each other, or one under another.
I was searching for the way to do it but I wasn't able to find anything. I tried to search how to put multiple scenes into one stage...
How to put multiple LineCharts
into one scene...
etc...
Without any success.
This is my code:
private void drawGraph(Stage stage, Double[] axisValues) {
//defining the axes
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Time");
//creating the chart
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Axis' values");
//defining a series
XYChart.Series series = new XYChart.Series();
series.setName("X Axis");
//populating the series with data
for (int i = 1; i<33; i++){
series.getData().add(new XYChart.Data(i, axisValues[i]));
}
//Scene scene = new Scene(lineChart,800,600);
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
stage.setScene(scene);
stage.show();
}
Problem
There are only one scene in one stage (window), so you are not able to add more than one scene to the same stage. But you are able to change the scene of a stage.
Solution
In Scene Builder you are able to see the possible solution in a preview. Add the three LineCharts to a FlowPane, and after that, add the FlowPane to the scene.
There was some type safety problems in your code, so I created a whole example to show you how you could do it.
Result