[英]JavaFX BarChart bar color
How can you change the color of a bar in a JavaFX BarChart
? 如何更改JavaFX BarChart
栏的颜色?
I couldn't find a way to change the color through the css setStyle
Method. 我找不到通过css setStyle
方法改变颜色的方法。
you can set color of bar using css 你可以用css设置bar的颜色
.default-color0.chart-bar { -fx-bar-fill: ***** }
.default-color1.chart-bar { -fx-bar-fill: ***** }
...
Using setStyle Method : 使用setStyle方法:
use lookupAll method in Node class, 在Node类中使用lookupAll方法,
Finds all Nodes, including this one and any children, which match the given CSS selector. 查找与给定CSS选择器匹配的所有节点,包括此节点和任何子节点。 If no matches are found, an empty unmodifiable set is returned. 如果未找到匹配项,则返回空的不可修改集。 The set is explicitly unordered. 该集明确无序。
code : 代码:
//set first bar color
for(Node n:barChart.lookupAll(".default-color0.chart-bar")) {
n.setStyle("-fx-bar-fill: red;");
}
//second bar color
for(Node n:barChart.lookupAll(".default-color1.chart-bar")) {
n.setStyle("-fx-bar-fill: green;");
}
From JavaFX8 you can simply use the .chart-bar
selector: 从JavaFX8开始,您只需使用.chart-bar
选择器:
.chart-bar {
-fx-bar-fill: red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.