我最近问了一个关于在JavaFX LineChart上添加两条垂直线的问题,现在我遇到了将一些样式的东西应用到图中的问题.我认为这是一个新问题所以我开了一个新线程.
我的问题:我怎样才能改变系列的不同颜色?我也想把背景改成白色.
以下是我创建的图表(它扩展了LineChart):
LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(xAxis, yAxis, dataset);
xAxis.setLabel("time(s)");
yAxis.setLabel("deg/s");
chart.setStyle(".chart-series-line { -fx-stroke-width: 2px; -fx-effect: null; ");
chart.setStyle(".default-color0.chart-series-line { -fx-stroke: blue; }");
chart.setStyle(".default-color1.chart-series-line { -fx-stroke: red; }");
chart.setStyle(".default-color0.chart-line-symbol { -fx-stroke: blue, blue; }");
chart.setStyle(".default-color1.chart-line-symbol { -fx-stroke: red, red; }");
chart.setStyle(".chart-legend { -fx-background-color: transparent; }");
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这些代码不适用于图表.所以我尝试使用CSS文件.
以下是CSS文件:
@CHARSET "ISO-8859-1";
.chart-series-line {
-fx-stroke-width: 1px;
-fx-effect: null;}
.default-color0.chart-series-line { -fx-stroke: blue; }
.default-color1.chart-series-line { -fx-stroke: red; }
.default-color0.chart-line-symbol { -fx-background-color: blue, blue; }
.default-color1.chart-line-symbol { -fx-background-color: red, red; }
.chart-legend {
-fx-background-color: transparent;
-fx-font-size: 0.75em;}
.chart-legend-item-symbol{
-fx-background-radius: 2;}
.chart-plot-background {
-fx-background-color: transparent;}
Run Code Online (Sandbox Code Playgroud)
我尝试遵循使用JavaFX图表:使用CSS设置样式图,但我在控制台中收到错误"警告:CSS错误解析文件:...:预期LBRACE在[1,9]"
我今天刚从JDK 7切换到JDK 8,所以我不确定它是否与此有关...
谢谢你的帮助!
Ada*_*dam 12
该@charset规则不支持JavaFX的CSS,这是唯一的全W3C CSS的一个子集.尝试删除它.
@规则
从JavaFX 8u20开始,CSS @import也得到部分支持.仅支持无条件导入.换句话说,不支持媒体类型限定符.此外,JavaFX CSS解析器与样式表中可能出现@import的位置不一致(请参阅At-rules).提醒用户,这将在以后的版本中修复.强烈建议遵守W3C标准.