我尝试在这段代码中动态设置我的 AreaChart
系列的样式,但它不起作用。我想在不通过 CSS 的情况下更改每个系列的背景。
XYChart.Series series1 = new XYChart.Series();
series1.getNode().setStyle("chart-series-area-fill { -fx-fill: transparent; }");
最佳答案
解决方案
在舞台上显示图表后使用以下代码:
// look up first series fill.
Node node = ac.lookup(".default-color0.chart-series-area-fill");
// set the first series fill to translucent pale green
node.setStyle("-fx-fill: rgba(152, 251, 152, 0.5);");
为什么你的方法不起作用
您不能在 setStyle 中应用 css 选择器根据 javadoc 调用:
this variable contains style properties and values and not the selector portion of a style rule.
关于css - 如何使用 JavaFX 以编程方式设置 AreaChart 系列的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20906489/