Setting javafx linechart line width


Question

I am trying to embed a javafx line chart in a swing application. It is showing up fine inside my application, but when i try to change the width of the lines i am stuck. I don't know how the css styling is supposed to work. I see LineChart has a setStyle which i tried to utilize from an example:

lineChart.setStyle(".chart-series-line {    \n"
        + "    -fx-stroke-width: 2px;\n"
        + "}");

but no change is shown, i then tried to lookup my series

for (int i = 0; i <= value; i++) {
     Set<Node> lookupAll = lineChart.lookupAll(".series" + i);
      for (Node n : lookupAll) {
         n.setStyle("-fx-stroke-width: 3px;");
     }
 }

now the lines changed width vertically but not horizontally.

1
1
7/1/2013 1:33:54 PM

Accepted Answer

It seems my problem came from the symbols.

I had 365 items on the x axis, which made it paint the symbols on top of each other making it look like i really thick line. I could fix this by disabling the symbols

lineChart.setCreateSymbols(false);
3
7/1/2013 1:41:14 PM

Add the following style in your CSS file :

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

and use StyleClass instead of Style :

lineChart.getStyleClass().add("thick-chart");

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon