我在 javafx 场景生成器中正确初始化了一个条形图。
我的控制器的代码如下:
@FXML
private BarChart<String, Integer> barChart;
@FXML
private CategoryAxis xAxis;
@FXML
private NumberAxis yAxis;
private XYChart.Series<String, Integer> series1;
/**
* Initializes the controller class. automatically called after the fxml file has been loaded.
*/
@FXML
private void initialize() {
series1 = new XYChart.Series();
series1.setName("myname");
series1.getData().add(new Data<String, Integer>("", 100));
barChart.getData().addAll(series1);
}
Task<Integer> task = new Task<Integer>() {
@Override
protected Integer call() throws Exception {
/* now I have to update my barchart. I tried to write few lines like this
but I'm not be able to update the values of the series1 in my barchart:
series = new XYChart.Series();
int newValue = 50;
series.getData().add(new XYChart.Data("", newValue));
barChart.getData().set(0, series);
*/
return null;
}
};
}
upd:任务功能在后台运行并正常工作。我认为唯一的问题是再次设置系列新值的代码