条形图中的动态数据无法正常工作 javaFX

Dynamic data in barchart not working properly javaFX

我正在尝试从结果集中加载数据,但是当显示图表时,一些条柱丢失了。

以下是我的代码:

        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);
        }

您必须为每个 row-data、

创建一个新系列
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<>);
}
if(count>0) {// This means array has atleast one value stored
    for(i=0; i<count; i++)
    {
      amount = Double.parseDouble(categs[i].replaceAll(",", ""));
      Series<String, Number> series1 = new XYChart.Series<String,Number>();
      series1.getData().add(new XYChart.Data<>("", amount));
      categoChart.getData().add(series1);
      
    }//END for loop 
}//END if(count>0)