I have a JavaFX app where I want the user to be able to control the symbols, linestyles, etc. in a lineChart. Rather than create multiple stylesheets, I want to build this functionality into the Java code. Thanks to Jewelsea's excellent previously posted example, I can dynamically change the line style, which is great! But I'm not managing to change the default symbol style. It is not clear to me how much of the .css statements can be used verbatim inline in a call to node.setStyle. Ie, I see that '-fx-*' commands work from Java code. But symbols in the .css file are defined with a different syntax, and merely inserting the css lines into my code in Java is not working. Here is an example from my code:StringBuilder styleString = new StringBuilder(); // do some stylin' switch (getLineStyle.getValue().toString()) { case "Line and points": styleString.append("-fx-stroke: blue; -fx-stroke-width: 2; "); styleString.append( ".chart-symbol {-fx-background-color: blue; -fx-background-radius: 3px;}"); engChart.setCreateSymbols(true); break; case "Line only": styleString.append("-fx-stroke: blue; -fx-stroke-width: 2; "); engChart.setCreateSymbols(false); break;In case "lines and points", I am able to control the color and width using this code, but the attempt to control the symbols fails miserably. I took the syntax from here: http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#introscenegraphIf there is a better reference to use to do this sort of control inline, I'd appreciate knowing what it is. Can anyone tell me how I might manipulate the symbols properly, inline? Thanks. 解决方案 You can't append a styleclass definition in a style string.You can only define style classes in a css file.So create and load your own css file and either override the existing symbol style or create your own.The default stylesheet for JavaFX 2.2 contains the following definitions:.chart-line-symbol { -fx-background-color: #f9d900, white; -fx-background-insets: 0, 2; -fx-background-radius: 5px; -fx-padding: 5px;}.default-color0.chart-line-symbol { -fx-background-color: #f9d900, white; }.default-color1.chart-line-symbol { -fx-background-color: #a9e200, white; }.default-color2.chart-line-symbol { -fx-background-color: #22bad9, white; }.default-color3.chart-line-symbol { -fx-background-color: #0181e2, white; }.default-color4.chart-line-symbol { -fx-background-color: #2f357f, white; }.default-color5.chart-line-symbol { -fx-background-color: #860061, white; }.default-color6.chart-line-symbol { -fx-background-color: #c62b00, white; }.default-color7.chart-line-symbol { -fx-background-color: #ff5700, white; }So either provide your own .chart-line-symbol definition or add a new style class to your chart, for example chart.getStyleClass().add("custom-chart"), then define a custom chart symbol in your css file..custom-chart .chart-line-symbol { -fx-background-color: #f9d900, firebrick; -fx-background-radius: 0px;}There are other ways to achieve custom styling of chart symbols, but it is probably best to use just css unless it really can't work for your use case. 这篇关于以编程方式内联控制lineCharts中的符号等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 18:06