简体   繁体   中英

Dynamic data in barchart not working properly javaFX

I am trying to load data from a result set but when the chart is displayed some of the bars are missing.

Following is my code:

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

You have to create a new series for each 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<>);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM