更改单个折线图系列颜色JavaFX [英] Changing individual line chart series color JavaFX

查看:247
本文介绍了更改单个折线图系列颜色JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,其中包含三个不同的折线图。我试图分别设置每个折线图系列的颜色。现在我有一个css文件,其内容如下:

I have a window that has three different line charts in it. I am trying to set the color of each line chart series individually. Right now I have a css file that has something like this:

.default-color0.chart-series-line { -fx-stroke: blue }
.default-color1.chart-series-line { -fx-stroke: black }

这是在每个图表中设置系列颜色的方法。例如,如果我的折线图有两个系列,一个是蓝色,另一个是黑色。但是使用此设置,所有三个具有一个系列的图表都默认设置为蓝色。

What this does is set the colors of series in each chart. For example, if I have a line chart that has two series, one would be blue, the other would be black. But with this setting, all three charts with one series default to blue.

我要实现的目标是分别设置系列,以便我的第一个折线图具有someColor1 ,第二个折线图包含someColor2,等等。

What I am trying to achieve is setting the series individually, so that my first line chart has someColor1, the second line chart has someColor2, etc.

我尝试了很多事情,并在整个Internet上进行了搜索,但是我要么见过 guess,但均不起作用,或通过CSS设置默认值的方法。有人解决这个问题吗?

I have tried many things, and searched all over the internet, but I have either seen "guesses" which do not work, or ways to set the default through css. Does anyone have a solution to this issue?

我正在尝试使用 lineChart.setStyle(-fx-stroke:green设置样式);

推荐答案

单独引用节点(而不是按类分组) CSS文件,您需要在节点上添加 id

To reference nodes individually (instead of grouped by class) in a CSS file, you need to add an id to the node:

LineChart<Number, Number> chart1 =  ... ;
LineChart<Number, Number> chart2 =  ... ;
LineChart<Number, Number> chart3 =  ... ;

chart1.setId("chart1");
chart2.setId("chart2");
chart3.setId("chart3");

显然,您可以选择描述每个图表的更有意义的ID。

Obviously, you can choose more meaningful ids that describe what each chart is.

然后可以在CSS中完成

Then in your CSS you can do

#chart1 .chart-series-line { -fx-stroke: blue }
#chart2 .chart-series-line { -fx-stroke: black }
#chart3 .chart-series-line { -fx-stroke: green }

这篇关于更改单个折线图系列颜色JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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