Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+5 votes

Does anyone know how to change the color of the line on the linechart?

asked in CSC305 Fall 2019 by (1 point)

2 Answers

0 votes

I was looking this up and unbelievably got nowhere. According to multiple websites, you should use css. So if you know css that should be the answer. I was thinking there might be a setFill() method for the line chart somehow but I couldn't find that either. I know this isn't a complete answer but it looks like css is the only choice.

answered by (1 point)
0 votes

In general the way preferred way to style charts is without code, using only css stylesheets as jschoen recommends. Additionally, if further customization is required, you can use css lookups from code to dig into the the nodes generated from series data and apply various additional css styling.

Here is information about dynamically changing a JavaFX line chart style and a sample program to go with the answer. In the sample app, all of the additional css styling is done via a setStyle call from code. Using a similar lookup technique, you could get access to the series nodes to apply an appropriate stylesheet styleclass rather than a setStyle call.

answered by (1 point)