JavaFX和SceneBuilder动态地将值分配给条形图

时间:2013-09-25 01:19:40

标签: java javafx-2 javafx bar-chart scenebuilder

我在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:任务函数在后台运行并正常工作。我认为唯一的问题是代码再次设置系列的新值

0 个答案:

没有答案