所以我有了这个JavaFX应用程序,我用SceneBuilder创建了4个饼图并将它们添加到场景中。然后我查询我的数据库以获取一些数据,并将其设置为下面方法中的饼图。然而,发生了一些非常奇怪的事如果我在更新发生时查看当前场景,一切正常。如果我正在查看不同的场景,则不会显示饼图。请帮忙。如果重要,get方法不涉及任何计算。
字段:
@FXML
private PieChart pieGender;
@FXML
private PieChart pieAge;
@FXML
private PieChart pieIncome;
@FXML
private PieChart pieContext;
更新方法:
//extracts and display data on this panel
public synchronized void updatePanelData() {
//update from the fx thread
Platform.runLater(() -> {
ObservableList<PieChart.Data> gender = FXCollections.observableArrayList(
new PieChart.Data("Male", this.dataRetriever.getGenderMale()),
new PieChart.Data("Female", this.dataRetriever.getGenderFemale())
);
this.pieGender.setData(gender);
ObservableList<PieChart.Data> age = FXCollections.observableArrayList(
new PieChart.Data("<25", this.dataRetriever.getAgeLessThan25()),
new PieChart.Data("25-34", this.dataRetriever.getAge25To34()),
new PieChart.Data("35-44", this.dataRetriever.getAge35To44()),
new PieChart.Data("45-54", this.dataRetriever.getAge45To54()),
new PieChart.Data(">54", this.dataRetriever.getAgeOver54())
);
this.pieAge.setData(age);
ObservableList<PieChart.Data> income = FXCollections.observableArrayList(
new PieChart.Data("Low", this.dataRetriever.getLowIncome()),
new PieChart.Data("Medium", this.dataRetriever.getMedIncome()),
new PieChart.Data("High", this.dataRetriever.getHighIncome())
);
this.pieIncome.setData(income);
ObservableList<PieChart.Data> context = FXCollections.observableArrayList(
new PieChart.Data("News", this.dataRetriever.getContextNews()),
new PieChart.Data("Shopping", this.dataRetriever.getContextShopping()),
new PieChart.Data("Social Media", this.dataRetriever.getContextSocialMedia()),
new PieChart.Data("Blog", this.dataRetriever.getContextBlog()),
new PieChart.Data("Hobbies", this.dataRetriever.getContextHobbies()),
new PieChart.Data("Travel", this.dataRetriever.getContextTravel())
);
this.pieContext.setData(context);
this.labelClick.setText(this.dataRetriever.getNumberOfClicks().toString());
this.labelServer.setText(this.dataRetriever.getServerNumber().toString());
this.labelImpression.setText(this.dataRetriever.getNumberOfImpressions().toString());
this.updateDateFilter();
});
}