JavaFX BarChart条形图颜色 [英] JavaFX BarChart bar color

查看:504
本文介绍了JavaFX BarChart条形图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改JavaFX中的条形颜色 BarChart

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

我找不到通过css setStyle 方法更改颜色的方法。

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

推荐答案

你可以使用css设置bar的颜色

you can set color of bar using css

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

使用setStyle方法:

Using setStyle Method :

使用 lookupAll 方法,


查找与$ b $匹配的所有节点,包括此节点和任何子节点b给出CSS选择器。如果未找到匹配项,则返回空的不可修改集
。该集明确无序。

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.

代码:

  //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;");
        }

这篇关于JavaFX BarChart条形图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆