How to set specific color to JavaFX XYChart.Series?

后端 未结 4 1504
旧时难觅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条回答
  •  长情又很酷
    2020-12-06 07:19

    I found a this Oracle Document on Styling charts with CSS and on that page scroll down to Setting Chart Colors for what you are specifically looking for.

    How to set a color to linecharts?

    The simplest way for this is the following CSS snippet:

    .default-color0.chart-series-line { -fx-stroke: #e9967a; }
    .default-color1.chart-series-line { -fx-stroke: #f0e68c; }
    .default-color2.chart-series-line { -fx-stroke: #dda0dd; }
    

    This unfortunately will not work by id or which series, but rather the order the series are placed in the graph. You can also set the line styles though by doing:

    .chart-series-line {    
        -fx-stroke-width: 2px;
        -fx-effect: null;
    }
    

    How to set a css class to series?

    Unfortunately I do not see a way to do that. It would be nice to be able to create CSS rules based off the XYChart.Series name property, but I do not think that is possible.

提交回复
热议问题