JavaFx PieChart: control size

2019-08-14 15:36发布

问题:

(I'm new to JavaFX.)

I'm adjusting an application developed in JavaFX that uses lots of pie charts depicted next to each other, all as children of the same HBox.

The charts don't have the same number of categories, and for some reason some of them become bigger than others.

Is there any way to control their radii? I would prefer all of them to have the same radius for some uniformity.

回答1:

Though there is no public API to directly control the radius of the PieChart, but you can control it using the different public methods of Region.

The pie-radius depends on the Height and Width of the enclosing region. The radius when labels are absent is controlled by the following piece of code inside PieChart.

// Code from PieChart.java
if(!shouldShowLabels) {
     pieRadius = Math.min(contentWidth,contentHeight) / 2;
}

So you can use a combination of various width and height methods available to control the size of the pie chart. You can use min and max properties to specify min and max region space respectively.



标签: charts javafx