java barchart类,JavaFX BarChart条形图颜色

本文介绍了如何在JavaFX BarChart中通过CSS和节点操作改变条形图的颜色,包括使用`.default-color0.chart-bar`和`.default-color1.chart-bar`样式选择器,并展示了如何使用`lookupAll`方法和`setStyle`方法来分别设置不同条目的颜色。
摘要由CSDN通过智能技术生成

How can you change the color of a bar in a JavaFX BarChart?

I couldn't find a way to change the color through the css setStyle Method.

解决方案

you can set color of bar using css

.default-color0.chart-bar { -fx-bar-fill: ***** }

.default-color1.chart-bar { -fx-bar-fill: ***** }

...

Using setStyle Method :

use lookupAll method in Node class,

Finds all Nodes, including this one and any children, which match the

given CSS selector. 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;");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值