JavaFX堆叠条形图图例颜色don';不遵循图表颜色CSS样式
在我的应用程序(JDK1.8u51)中,我想为StackedBarChart中的某些数据类别设置一些特定的颜色。我用CSS制作了这个,如下所示:JavaFX堆叠条形图图例颜色don';不遵循图表颜色CSS样式,css,charts,javafx,legend,Css,Charts,Javafx,Legend,在我的应用程序(JDK1.8u51)中,我想为StackedBarChart中的某些数据类别设置一些特定的颜色。我用CSS制作了这个,如下所示: .root{ -fx-ok-color: darkgreen; -fx-critical-color: darkblue; -fx-warning-color: gold; -fx-minor-color: orange; -fx-major-color: red; -fx-undefined-color
.root{
-fx-ok-color: darkgreen;
-fx-critical-color: darkblue;
-fx-warning-color: gold;
-fx-minor-color: orange;
-fx-major-color: red;
-fx-undefined-color: darkgrey;
}
.okChartBar{
-fx-bar-fill : -fx-ok-color;
}
.warnigChartBar{
-fx-bar-fill : -fx-warning-color;
}
.minorChartBar{
-fx-bar-fill : -fx-minor-color;
}
.majorChartbar{
-fx-bar-fill : -fx-major-color;
}
.criticalChartBar{
-fx-bar-fill : -fx-critical-color;
}
.undefinedChartBar{
-fx-bar-fill : -fx-undefined-color;
}
我在我的代码中使用CSS,如下所示:
StackedBarChart barChart = new StackedBarChart(new CategoryAxis(), new NumberAxis());
barChart.setTitle("Title");
vBox.getChildren().add(1,barChart);
barChart.setAnimated(true);
barChart.getData().addAll(barChartData());
barChart.getData().forEach(data ->{
XYChart.Series moduleSerie = (XYChart.Series)data;
moduleSerie.getData().forEach(item ->{
XYChart.Data item2 = (XYChart.Data)item;
item2.getNode().getStyleClass().add(styleLink.get(moduleSerie.getName()));
// styleLink is a map which containt the link from the alarm type (minor, major....) to the CSS style (minorChartbar, majorChartbar, ...)
});
});
我得到的是这样一个堆叠条形图:
如您所见,图表区域和图例之间的颜色不同。“临界”值必须为蓝色,“主要”值必须为红色
这是一个JavaFX错误还是仅仅是我的代码
很抱歉,这篇文章太长,我只想尽可能完整。对于那些搜索的人,我在另外两个问题上找到了答案:
.chart legend item symbol
,如下所示:
.okChartBar .chart-legend-item-symbol{
-fx-background-color:-fx-ok-color;
}
对于搜索者,我在另外两个问题上找到了答案:
.chart legend item symbol
,如下所示:
.okChartBar .chart-legend-item-symbol{
-fx-background-color:-fx-ok-color;
}
嗨,我有同样的问题,但是两个答案中的代码片段对我都不起作用。你能帮我吗?嗨,我有同样的问题,但是两个答案中的代码片段对我都不起作用。你能帮我吗?