A DESCRIPTION OF THE PROBLEM :
When setting the categories manually in CategoryAxis, autoranging is automatically turned off. This prevents the axis labels from automatically rotating if there is a lack of horizontal space. However, Axis is rotating the labels to determine the preferred height for the axis, and so there is a lot of blank space that is unused as a result.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached JavaFX application. You will notice that there is a lot of empty space beneath the chart when it is not wide enough for all of the category labels to fit. This is because the chart axis is rotating the labels when calculating its preferred height, but then not rotating the labels when performing the layout because autoRanging is set to false.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the chart to fill the parent VBox vertically since its preferred height is bound to the height of the parent VBox.
ACTUAL -
The chart does not fill the parent VBox until it is wide enough for all of the category labels to show in their entirety.
---------- BEGIN SOURCE ----------
import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(final Stage primaryStage) {
var chartBox = new VBox();
var categories = List.of(
"1st very long category name..............",
"2nd very long category name..............",
"3rd very long category name..............",
"4th very long category name..............",
"5th very long category name.............."
);
var xAxis = new CategoryAxis();
xAxis.setCategories(FXCollections.observableList(categories));
var chart = new BarChart<>(xAxis, new NumberAxis());
chart.prefWidthProperty().bind(chartBox.widthProperty());
chart.prefHeightProperty().bind(chartBox.heightProperty());
chart.setAnimated(false);
chartBox.getChildren().add(chart);
var scene = new Scene(chartBox);
primaryStage.setScene(scene);
primaryStage.show();
}
}
---------- END SOURCE ----------
FREQUENCY : always
When setting the categories manually in CategoryAxis, autoranging is automatically turned off. This prevents the axis labels from automatically rotating if there is a lack of horizontal space. However, Axis is rotating the labels to determine the preferred height for the axis, and so there is a lot of blank space that is unused as a result.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached JavaFX application. You will notice that there is a lot of empty space beneath the chart when it is not wide enough for all of the category labels to fit. This is because the chart axis is rotating the labels when calculating its preferred height, but then not rotating the labels when performing the layout because autoRanging is set to false.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the chart to fill the parent VBox vertically since its preferred height is bound to the height of the parent VBox.
ACTUAL -
The chart does not fill the parent VBox until it is wide enough for all of the category labels to show in their entirety.
---------- BEGIN SOURCE ----------
import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(final Stage primaryStage) {
var chartBox = new VBox();
var categories = List.of(
"1st very long category name..............",
"2nd very long category name..............",
"3rd very long category name..............",
"4th very long category name..............",
"5th very long category name.............."
);
var xAxis = new CategoryAxis();
xAxis.setCategories(FXCollections.observableList(categories));
var chart = new BarChart<>(xAxis, new NumberAxis());
chart.prefWidthProperty().bind(chartBox.widthProperty());
chart.prefHeightProperty().bind(chartBox.heightProperty());
chart.setAnimated(false);
chartBox.getChildren().add(chart);
var scene = new Scene(chartBox);
primaryStage.setScene(scene);
primaryStage.show();
}
}
---------- END SOURCE ----------
FREQUENCY : always
- links to
-
Review openjdk/jfx/342