有没有办法将JavaFX中LineChart的最小大小设置为小于200×150像素?

huangapple go评论57阅读模式
英文:

Is there a way to set minimum size of a LineChart in javafx to less than 200x150 pixels?

问题

我正在尝试在一个窗口上显示24个LineCharts,窗口布局为4行6列,如图所示。窗口尺寸为1368x912像素。

我面临的问题是,我需要在比上面图像中显示的窗口尺寸更小的窗口上显示24个LineCharts,但LineChart的最小尺寸是200x150像素(至少我无法使它更小)。

是否有办法重写LineChart类以使其能够变得更小?

英文:

I am trying to display 24 LineCharts on a window 4 rows and 6 columns as shown in the picture. The window size is 1368x912 px.

The problem I am facing is that I need to show 24 LineCharts on a smaller window than shown on the upper image, but the smallest size of a LineChart is 200x150 px (at least I can't make it smaller).

Is there any way to overwrite the LineChart class to enable it to make it smaller?

答案1

得分: 2

在一番搜索后,我发现解决方案相当简单。

您需要覆盖lineChart的maxSize和minSize属性,使它们具有相同的大小:

lineChart.setMaxSize(double, double);
lineChart.setMinSize(double, double);

如果最小大小大于最大大小,那么最小大小将优先。

您还可以使用CSS文件来调整图表的填充,可以像这样导入:

lineChart.getStylesheet().add("path/to/stylesheet.css");

参考fx-css

英文:

After a bit of searching, I found the solution to be quite simple.

You need to overwrite the maxSize and minSize properties of the lineChart with the same size:

lineChart.setMaxSize(double, double);
lineChart.setMinSize(double, double);

If the minimum size is bigger than the maximum size, the minimum size will overrule.

You can also adjust padding of a chart using a css file, which can be imported like this:

lineChart.getStylesheet().add("path/to/stylesheet.css");

Reference for fx-css.

huangapple
  • 本文由 发表于 2023年6月26日 14:27:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554029.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定