Reputation: 169
I would like to increase the radius of a JavaFX pie chart because the default dimensions render a chart that is too small. I understand (from an answer posted by @ItachiUchiha 4 years ago) that it is impossible to directly manipulate the dimensions of a pie chart with a call like:
piechart = new PieChart(pieChartData);
piechart.setPrefHeight(600); // no effect
piechart.setPrefWidth(600); // no effect
The answer posted by @ItachiUchiha suggests using an instance of Region and indeed the following does achieve this:
Region region = new Region();
region.setMaxHeight(600);
region.setMaxWidth(600);
region.setPrefHeight(600);
region.setPrefWidth(600);
region.setMinHeight(600);
region.setMinWidth(600);
However I can't get the piechart into the instance of Region. Intuitively I tried:
region.getChildren().add(piechart);
and
Region region = new Region(piechart);
but these are syntactically wrong.
I know that the pie chart is rendering the Data properly because it displays ok with the code:
detailPane.getChildren().add(piechart);
piechart.setVisible(true);
But this just renders the pie chart with its default radius. How to I 'link' the pie chart to the instance of Region and get it to resize as required?
Upvotes: 1
Views: 763
Reputation: 169
I seem to have solved the issue through .css by adding the following to the stylesheet:
.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;
}
The chart dimensions exactly match the anchorpane size of the right hand split pane. The result is a very nicely sized and well proportioned pie chart centered exactly in the pane.
Upvotes: 1