0
votes

I have JavaFX LineChart and some data with XYChart.Series objects as

XYChart.Series<String, Number> series = new XYChart.Series<String, Number>();
series.getData().add(new XYChart.Data<>(key, percent));
lineChart.getData().add(series);

I am trying to style the LineChart lines with JavaFX CSS (preferably inline) with not much luck. I have tried numerous things but thought

series.getNode().setStyle("-fx-stroke: blue;");

should work and it doesn't.

In the JavaFX CSS Reference LineChart section it gives this information,

"chart-series-line series < i > default-color < j >" Where < i > is the index of the series and < j > is the series’ color index

What is the index of a series and the index of a color? I have searched StackOverflow, this question does not seem to have been answered, at least not with any working solutions.

1
do you have a css file where you handle all the styles or are you setting them directly through FX? - beastlyCoder
I do not have a css file, I was attempting to do it all inline, through FX, but I now question if that is wise. - Diz
I think the best decision would be to create a CSS file. - beastlyCoder
Whenever I've worked with JavaFX I have always used a CSS file, it was rare that I used inline methods to do it. It also helps with keeping the code organized as well. - beastlyCoder

1 Answers

0
votes

The series.getNode().setStyle("-fx-stroke: blue;"); must appear after the lineChart.getData().add(series);

lineChart.getData().add(series);
series.getNode().setStyle("-fx-stroke: blue;");

worked as long as the two lines are in this order. This may have something to do with JavaFX CSS mimicking the DOM, I really don't know though. Ridiculous.