I'm using a line chart with JavaFX:
LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
XYChart.Series series = new XYChart.Series();
lineChart.getData().add(series);
I want to add data to the series successively, thereby the order in which the values arrive can not be predicted. For example, the index can be between 0 and the current size of the series.
series.getData().add(new XYChart.Data(index, value));
Consider the following scenario:
//initializing...
series.getData().add(new XYChart.Data(1, 400));
series.getData().add(new XYChart.Data(3, 500));
series.getData().add(new XYChart.Data(8, 100));
series.getData().add(new XYChart.Data(12, 120));
series.getData().add(new XYChart.Data(20, 300));
//later...
series.getData().add(new XYChart.Data(2, 450));
series.getData().add(new XYChart.Data(5, 300));
series.getData().add(new XYChart.Data(15, 200));
The problem is how the graph is depicted. In the example above, at index 20 the graph makes a loop back to index 2. It looks like this:
But I want it to look like this:
What settings are necessary to update the graph properly without additional lines crossing the graph?