Changing individual line chart series color JavaFX

后端 未结 1 1192
长情又很酷
长情又很酷 2021-01-27 09:51

I have a window that has three different line charts in it. I am trying to set the color of each line chart series individually. Right now I have a css file that has something l

相关标签:
1条回答
  • 2021-01-27 10:49

    To reference nodes individually (instead of grouped by class) in a CSS file, you need to add an id to the node:

    LineChart<Number, Number> chart1 =  ... ;
    LineChart<Number, Number> chart2 =  ... ;
    LineChart<Number, Number> chart3 =  ... ;
    
    chart1.setId("chart1");
    chart2.setId("chart2");
    chart3.setId("chart3");
    

    Obviously, you can choose more meaningful ids that describe what each chart is.

    Then in your CSS you can do

    #chart1 .chart-series-line { -fx-stroke: blue }
    #chart2 .chart-series-line { -fx-stroke: black }
    #chart3 .chart-series-line { -fx-stroke: green }
    
    0 讨论(0)
提交回复
热议问题