我想增加JavaFX饼图的半径,因为默认维度呈现的图表太小。我知道(从4年前@ItachiUchiha发布的答案中),不可能通过调用直接操作饼图的尺寸,例如:
piechart = new PieChart(pieChartData);
piechart.setPrefHeight(600); // no effect
piechart.setPrefWidth(600); // no effect
@ItachiUchiha发布的答案建议使用Region的实例,实际上,下面的示例实现了这一点:
Region region = new Region();
region.setMaxHeight(600);
region.setMaxWidth(600);
region.setPrefHeight(600);
region.setPrefWidth(600);
region.setMinHeight(600);
region.setMinWidth(600);
但是,我无法将片段图放入Region的实例中。凭直觉,我尝试了:
region.getChildren().add(piechart);
and
Region region = new Region(piechart);
但这些在语法上是错误的。
我知道饼图正确地呈现了数据,因为它显示的代码没有问题:
detailPane.getChildren().add(piechart);
piechart.setVisible(true);
但这只是使用其默认半径呈现饼图。如何将饼图链接到Region的实例,并根据需要调整大小?
发布于 2019-10-07 10:51:33
通过在样式表中添加以下内容,我似乎已经通过.css解决了这个问题:
.chart {
-fx-pref-width: 916;
-fx-pref-height: 620;
-fx-min-width: 916;
-fx-min-height: 620;
-fx-max-width: 916;
-fx-max-height: 620;
}
.chart-content {
-fx-padding: 20px;
}
图表尺寸与右侧拆分窗格的锚点窗格大小完全匹配。结果是一个非常好的大小和适当比例的饼图,恰好在窗格中居中。
https://stackoverflow.com/questions/58262331
复制相似问题