gpt4 book ai didi

java - 如何在JavaFx中获取折线图刻度标签的宽度?

转载 作者:行者123 更新时间:2023-12-02 11:13:56 25 4
gpt4 key购买 nike

如何获取下面屏幕截图中红色框突出显示部分的宽度?

chart

我已经尝试过

LineChart<Number, Number> sourceChart = ...;
NumberAxis axis = (NumberAxis) sourceChart.getXAxis();
FilteredList<Node> filtered = axis.getChildrenUnmodifiable().filtered(node -> node instanceof Text);
node = filtered.get(0);

filtered 是刻度列表,但 node 没有任何返回刻度宽度的方法,如 getPrefWidth() 或任何此类。

最佳答案

好吧,在 JKostikiadis 的帮助下我明白了。基本上,正如她/他提到的,您获得绘图区域的 layoutX,然后只需添加绘图区域的左侧填充。

Region plotArea = (Region) sourceChart.lookup("Region");
double plotAreaLayoutX = plotArea.getLayoutX();
double chartLeftPad = sourceChart.getPadding().getLeft();
double labelWidth = plotAreaLayoutX + chartLeftPad;

关于java - 如何在JavaFx中获取折线图刻度标签的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50420929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com