How to style programmatically an AreaChart series with JavaFX

1.4k views Asked by At

I am trying in this code to style dynamically my AreaChart series but it's not working. I want to change each series background without passing by CSS.

XYChart.Series series1 = new XYChart.Series();
series1.getNode().setStyle("chart-series-area-fill { -fx-fill: transparent; }");
1

There are 1 answers

0
jewelsea On BEST ANSWER

Solution

Use the following code after you have shown the chart on a stage:

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

Why your approach does not work

You can't apply a css selector in a setStyle call, according to the javadoc:

this variable contains style properties and values and not the selector portion of a style rule.