Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX堆叠条形图图例颜色don';不遵循图表颜色CSS样式_Css_Charts_Javafx_Legend - Fatal编程技术网

JavaFX堆叠条形图图例颜色don';不遵循图表颜色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

在我的应用程序(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: 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错误还是仅仅是我的代码


很抱歉,这篇文章太长,我只想尽可能完整。

对于那些搜索的人,我在另外两个问题上找到了答案:

我还必须在CSS中的每个样式类中添加
.chart legend item symbol
,如下所示:

.okChartBar .chart-legend-item-symbol{ 
    -fx-background-color:-fx-ok-color;
 }

对于搜索者,我在另外两个问题上找到了答案:

我还必须在CSS中的每个样式类中添加
.chart legend item symbol
,如下所示:

.okChartBar .chart-legend-item-symbol{ 
    -fx-background-color:-fx-ok-color;
 }

嗨,我有同样的问题,但是两个答案中的代码片段对我都不起作用。你能帮我吗?嗨,我有同样的问题,但是两个答案中的代码片段对我都不起作用。你能帮我吗?