我正在尝试从结果集中加载数据,但是当显示图表时,某些条形图丢失了。
以下是我的代码:
ResultSet rs = ps.executeQuery();
XYChart.Series<String, Double> series = new XYChart.Series<>();
while (rs.next()) {
String name = rs.getString(1);
Double no = rs.getDouble(2);
series.getData().add(new XYChart.Data<>(name, no));
barchart1.getData().add(series);
}
最佳答案
您必须为每个行数据创建一个新系列,
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
Double no = rs.getDouble(2);
XYChart.Series<String, Double> series = new XYChart.Series<>();
series.getData().add(new XYChart.Data<>(name, no));
barchart1.getData().add(new XYChart.Data<>);
}
关于java - 条形图中的动态数据无法正常工作javaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42325380/