Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following Controller for my window:

package window;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;

import java.util.Map;
import java.util.SortedMap;

public class StatisticsController {

    @FXML
    private BarChart<?, ?> barChartHistogram;

    private SortedMap<String, Integer> _points;

    @FXML
    private CategoryAxis xAxis;
    @FXML
    private NumberAxis yAxis;

    public void onLoad(SortedMap<String, Integer> points) {
        xAxis.setLabel("Numer indeksu");
        yAxis.setLabel("Ilo?? punktów");
        //barChartHistogram.setBarGap(0);
        XYChart.Series series1 = new XYChart.Series();
        int a = 10;
        series1.getData().add(new XYChart.Data("Tom", 10));
        series1.getData().add(new XYChart.Data("Andrew", 7));
        series1.getData().add(new XYChart.Data("Patrick", 5));


        /*for (Map.Entry<String, Integer> p: points.entrySet()) {
            series1.getData().add(new XYChart.Data<>(Integer.toString(a), p.getValue()));
            a += 10;
        }*/
        barChartHistogram.getData().addAll(series1);
        _points = points;
    }

}

The .fxml file for this window:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="window.StatisticsController">
   <children>
      <BarChart fx:id="barChartHistogram" layoutX="12.0" layoutY="14.0" prefHeight="372.0" prefWidth="1500.0">
        <xAxis>
          <CategoryAxis side="BOTTOM" fx:id="xAxis" />
        </xAxis>
        <yAxis>
          <NumberAxis fx:id="yAxis" side="LEFT" />
        </yAxis>
      </BarChart>
   </children>
</AnchorPane>

Everything works perfectly except one thing:

enter image description here

As you can see the x axis label works fine, but the x axis labels (I mean like column names), which should be Tom, Andrew and Patrick are placed in exact same position (through this mess you can actually read Patrick) a the 0 position of x axis. Where is the problem? Should I make some changes to the UI or something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
230 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found another work around for this. Simply set xAxis.setAnimated(false)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...