【发布时间】:2015-05-12 11:46:00
【问题描述】:
我最近问了一个关于在 JavaFX LineChart 上添加两条垂直线的问题,现在我在将一些样式内容应用于绘图时遇到了问题。我认为这是一个新问题,所以我打开一个新线程。
Add Two Vertical Lines to 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; }");
由于某种原因,这些代码不适用于图表。所以我尝试使用 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;}
我尝试关注Using JavaFX Charts: Styling Charts with CSS,但我在控制台中收到错误消息“警告:解析文件的 CSS 错误:...:预期 LBRACE 在 [1,9]”
我今天刚从 JDK 7 切换到 JDK 8,所以我不确定这是否与此有关...
感谢您的帮助!
【问题讨论】: