Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+3 votes

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

asked in CSC305 Fall 2019 by (2.1k points)

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 (2.7k points)
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 (2.2k points)
...