简体   繁体   中英

how to display labels in a BarChart for each bar using javafx

I wanted to display the category of each value in the BarChart but it seems as though all categories get displayed on top of each other like the image below

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

Have you tried to setCategories method from the CategoryAxis class?

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

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