How to set specific color to JavaFX XYChart.Series?

后端 未结 4 1500
旧时难觅i
旧时难觅i 2020-12-06 06:53

I am trying to style my JavaFX linechart, but can\'t find any way to set color to specific series. I know, that I can style via CSS, but I can\'t find how to set ID or CLASS

4条回答
  •  Happy的楠姐
    2020-12-06 07:02

    jewelsea's answer seems to state that you have to put a style-class on every node of the series. I'm using the following code to style the series of an area chart and only assign a class to the node associated with the series. Example code is in Scala, but should be easy to translate.

    When creating the series, I add a series-specific style class:

            val s = new XYChart.Series[Number, Number]()   //create a new series
            s.setName(seriesName)                          //set its name (display in legend)
            s.getNode.getStyleClass.add("series-" + seriesName)  //add specific style class
    

    Then inside the css-file I do the following to change the fill color of the series 'butterwings':

    .series-butterwings *.chart-series-area-fill{
        -fx-fill: #aab597; 
    }
    

    This works, because the node for the series area is below the series node (which is a group in case of area chart).

提交回复
热议问题