diff --git a/modules/controls/src/main/java/javafx/scene/chart/Chart.java b/modules/controls/src/main/java/javafx/scene/chart/Chart.java --- a/modules/controls/src/main/java/javafx/scene/chart/Chart.java +++ b/modules/controls/src/main/java/javafx/scene/chart/Chart.java @@ -361,8 +361,15 @@ } } else if (getLegendSide().equals(Side.BOTTOM)) { final double legendHeight = snapSize(legend.prefHeight(width-left-right)); - final double legendWidth = snapSize(legend.prefWidth(-1)); - legend.resizeRelocate(left + (((width - left - right)-legendWidth)/2), height-bottom-legendHeight, legendWidth, legendHeight); + final double legendWidth = Math.min(width-left-right, snapSize(legend.prefWidth(legendHeight))); + + // Fix for RT-32573 - this forces the columns/rows count to update accurately. + // Ideally we would have a better, more dynamic way of calculating the row/column + // fields in the Legend class, rather than just during the pref size calculations. + legend.prefHeight(legendWidth); + + final double x = Math.max(0, left + (((width - left - right) - legendWidth) / 2.0)); + legend.resizeRelocate(x, height-bottom-legendHeight, legendWidth, legendHeight); if ((height - bottom - top - legendHeight) < MIN_HEIGHT_TO_LEAVE_FOR_CHART_CONTENT) { shouldShowLegend = false; } else {