如何更改XYChart';JavaFx中的颜色是什么?

如何更改XYChart';JavaFx中的颜色是什么?,java,css,charts,javafx,bar-chart,Java,Css,Charts,Javafx,Bar Chart,如何更改条形图颜色 有人能给我一个线索吗 如何设置线条图的颜色 如何将css类设置为series 公共类hmw3扩展了应用程序{ @覆盖公共无效开始(阶段)引发异常{ 舞台剧名(“HİSTOGRAM”); 最终CategoryAxis xAxis=新CategoryAxis(); 最终数字xis yAxis=新数字xis(0,50,10); 最终条形图bc= 新柱状图(xAxis、yAxis); bc.赛特莱姆(“HİSTOGRAM”); 最终VBox verticalbox=新VBox()

如何更改条形图颜色

有人能给我一个线索吗

  • 如何设置线条图的颜色
  • 如何将css类设置为series
公共类hmw3扩展了应用程序{
@覆盖公共无效开始(阶段)引发异常{
舞台剧名(“HİSTOGRAM”);
最终CategoryAxis xAxis=新CategoryAxis();
最终数字xis yAxis=新数字xis(0,50,10);
最终条形图bc=
新柱状图(xAxis、yAxis);
bc.赛特莱姆(“HİSTOGRAM”);
最终VBox verticalbox=新VBox();
最终HBox水平框=新HBox();
最终按钮绘制=新按钮(“绘制”);
复选框红色=新复选框(“红色”);
红色。已选择(正确);
复选框蓝色=新复选框(“蓝色”);
最终文本字段TextField=新文本字段();
水平框。设置对齐(右下角位置);
水平盒。设置间隔(46);
字符串文件名=textfield.getText();
XYChart.Series系列1=新的XYChart.Series();
公元前800600年;
horizontalbox.getChildren().addAll(绘图、红色、蓝色、文本字段);
verticalbox.getChildren().addAll(bc,horizontalbox);
水平框。设置填充(新插图(10,10,10,50));
场景=新场景(新组());
((组)scene.getRoot()).getChildren().add(verticalbox);
舞台场景;
stage.show();
//如果单击按钮,则将其设置为操作
draw.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent事件){
试一试{
hmw34.occure(textfield.getText(),series1);
bc.getData().add(series1);
bc.setLegendVisible(假);
}catch(filenotfounde异常){
System.out.println(“错误:没有这样的文件”);
}
}
});
//伦吉尼·杜曾利耶克。
/**if(红色。isSelected())
bc.setStyle(“-fx条填充:#000080;”;//选中红色框
else if(blue.isSelected())
bc.setStyle(“-fx条填充:#b22222;”);//选中蓝色复选框*/
}
公共静态void main(字符串[]args){
发射(args);
}
}
datad.nodeProperty().addListener(新的ChangeListener()){
@凌驾

公共无效改变(ObservalEvalue在我尝试的不同可能性中,使用“setStyle”方法的Mevlana Ayas解决方案是唯一有效的

假设“color”是描述所需颜色的字符串。 例如:

String color = "hsb(0,0,0)";
String opaqueColor = "hsb(0,0,0,0.2)";
对于散点图、折线图、面积图,请在添加到序列的每个数据上添加以下侦听器:

data.nodeProperty().addListener(new ChangeListener<Node>() {
            @Override
            public void changed(ObservableValue<? extends Node> ov, Node oldNode, final Node node) {
                if (node != null ) {                   
                    node.setStyle(String.format("-fx-background-color: %s;", color));
                }
            }
}
data.nodeProperty().addListener(新的ChangeListener()){
@凌驾

public void changed(observeValue)你看过Oracle关于使用JavaFX图表的教程了吗?是的,看看。他们只给出了;图表系列线条{-fx笔划宽度:2px;-fx效果:null;}。默认-color0.chart-series-line{-fx笔划:{-e9967a;}.default-color1.chart-series-line{-fx-stroke:#f0e68c;}.default-color2.chart-series-line{-fx-stroke:#dda0dd;}但ı不知道如何在我的代码中使用。您熟悉使用CSS对应用程序进行蒙皮吗
data.nodeProperty().addListener(new ChangeListener<Node>() {
            @Override
            public void changed(ObservableValue<? extends Node> ov, Node oldNode, final Node node) {
                if (node != null ) {                   
                    node.setStyle(String.format("-fx-background-color: %s;", color));
                }
            }
}
serie.nodeProperty().addListener((ObservableValue<? extends Node> o, Node old, Node node) -> {
                if (node != null) {
                    if (node instanceof Path) {
                        node.setStyle(String.format("-fx-stroke: %s;", chartSerie.color));
                    } 
            });
serie.nodeProperty().addListener((ObservableValue<? extends Node> o, Node old, Node node) -> {
                if (node != null) {
                     if (node instanceof Group) {
                        // AreaChart, assuming FILL is FIRST child and LINE is SECOND child
                        Group group = (Group) node;
                        Path fill = (Path) group.getChildren().get(0);
                        fill.setStyle(String.format("-fx-fill: %s;", chartSerie.opaqueColor));
                        Path line = (Path) group.getChildren().get(1);
                        line.setStyle(String.format("-fx-stroke: %s;", chartSerie.color));
                    }
                }
            });