Is it possible to plot LocalTime
data on the X-axis in a LineChart
?
I would like dynamically added LocalTime
values on the X-axis to be sorted ascending.
When trying to add LocalTime
values on the X-axis using the code below, no data is drawn on the chart and my logger shows an error:
java.lang.ClassCastException: java.time.LocalTime cannot be cast to java.lang.String | Class name: javafx.scene.chart.CategoryAxis | Method name: toNumericValue
@FXML
private LineChart<LocalTime, Number> chart;
observer.addChart(chart);
and in Observer.java:
public void addChart(LineChart chart) {
this.chart = chart;
}
XYChart.Series<LocalTime, Number> series = new XYChart.Series<>();
chart.getData().add(series);
chart.getData().get(0).getData().add(new XYChart.Data<>(LocalTime.parse("11:05:45.207"), Integer.valueOf("5")));
When I use String
on the X-axis instead of LocalTime
, everything works fine. This error is somewhat similar to this: https://bugs.openjdk.org/browse/JDK-8092916