JavaFx中的java直方图
我有一个JavaFX程序,它显示一个直方图,以显示给定英文文本文件中每个字母的出现情况(不区分大小写)。 它还应该包含两个单选按钮,红色和蓝色,以更改列的颜色,它还应该包含一个“绘制”按钮。所以这意味着,你的直方图应该是空的,它可以用draw按钮填充。 我画了按钮部分。我创建我的专栏,并将我所做的一切添加到HBox中,HBox将保留我的屏幕
但是,我不能做单选按钮部分。ıt应在我单击“红色”按钮或“蓝色”按钮时改变颜色。但它什么也没做
以下是我的代码中我遇到的问题:
说明:图表是我的图表。ıts类型是条形图,而且,我使用XYChartSeries创建每个列,就像这样
XYChartSeries Sutun=新XYChartSeries
pane = new Pane();
VBox paneforcolorbutton = new VBox(20);
paneforcolorbutton.setPadding(new Insets(5 ,5 ,5, 5 ));
paneforcolorbutton.setStyle("-fx-border-color: green;");
paneforcolorbutton.setStyle("-fx-border-width: 2px ; -fx-border-color: green;");
RadioButton blue = new RadioButton("Blue");
RadioButton red = new RadioButton ("Red");
paneforcolorbutton.getChildren().addAll(red, blue);
ToggleGroup group = new ToggleGroup();
red.setToggleGroup(group);
blue.setToggleGroup(group);
red.setOnAction(e -> {
if (red.isSelected()){
Graph.setStyle("-fx-bar-fill-color: red;");
}
});
blue.setOnAction(e -> {
if (blue.isSelected()){
Graph.setStyle("-fx-bar-fill-color: blue;");
}
});
但它没有出现在我的直方图中。我做错了什么
# 1 楼答案
您好,再次感谢您的警告@MikaelOhlson我确实更新了我的问题,并且找到了解决方法。在这里,正确的代码; 但这里没有什么解释,图形的类型是条形图,我创建的每一列都是这样的; XYChartSeries Sutun=新XYChartSeries