如何使用javafx在条形图中显示每个条形的标签

px9o7tmv  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(237)

我想在条形图中显示每个值的类别,但似乎所有类别都显示在彼此的顶部,如下图所示
enter image description here

String query = "";
String destination = "";
try{
if(classe.isSelected()){
    PreparedStatement tableToGraph = con.prepareStatement(
            "SELECT  libelle_classe,avg(numseance) FROM Absence JOIN Etudiant on Etudiant.id_etudiant=Absence.id_etudiantA Join Classe on Etudiant.id_classeE=Classe.id_classe Group by libelle_classe"
    );
    ResultSet resultSet = tableToGraph.executeQuery();
    ArrayList<Double> numseance = new ArrayList<Double>();
    ArrayList<String> libelle_classe = new ArrayList<String>();
    while (resultSet.next()) {
        libelle_classe.add(resultSet.getString(1));
        numseance.add(resultSet.getDouble(2));
    }
    resultSet.close();
    for (int i = 0; i < numseance.size(); i++) {
        System.out.println(libelle_classe.get(i));
    }
    XYChart.Series<String, Double> dataSeries = new XYChart.Series();
    /*CategoryAxis xAxis = new CategoryAxis();
    xAxis.setLabel("Libelle Classe");
    CategoryAxis yAxis = new CategoryAxis();
    yAxis.setLabel("Avg des absences");*/
    dataSeries.setName("Taux d'Absenteisme pour chaque classe");
    for (int i = 0; i < numseance.size(); i++) {
        dataSeries.getData().add(new XYChart.Data(libelle_classe.get(i), numseance.get(i)));
    }
    income_data.getData().add(dataSeries);
efzxgjgh

efzxgjgh1#

您是否尝试过从CategoryAxis类调用setCategories方法?

CategoryAxis xAxis = new CategoryAxis();
xAxis.setLabel("Libelle Classe");
xAxis.setCategories(libelle_classe);
income_data.getData().add(dataSeries);

相关问题