JavaFX 2.0 - How to change legend color of a LineChart dynamically?

后端 未结 4 1870
醉话见心
醉话见心 2021-01-18 09:00

I am trying to style my JavaFX linechart but I have some trouble with the legend.

I know how to change the legend color of a line chart in the css file:

4条回答
  •  感动是毒
    2021-01-18 09:18

    For future reference, this problem can be solved by wrapping your relevant code in a call to Platform.runLater(). For example:

    LineChart plot;
    ....
    Platform.runLater(() -> {
        Node nl = plot.lookup(".default-color0.chart-series-line");
        Node ns = plot.lookup(".default-color0.chart-line-symbol");
    
        nl.setStyle("-fx-stroke: #333;");
        ns.setStyle("-fx-background-color: #333, white;");
    }); 
    

提交回复
热议问题