[英]JavaFX - Add new PieChart.Data to existing Pie Chart
I am curious how to add something to an already existing PieChart in JavaFx(i think im using 2.2.25, but i could update if it helps and if there is a newer version). 我很好奇如何在JavaFx中添加一些已经存在的PieChart(我认为即时通讯使用2.2.25,但如果它有帮助,我可以更新,如果有更新的版本)。
For instance: 例如:
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(new PieChart.Data("HD 7990", 65), new PieChart.Data("GTX 690", 35));
Now i want to 'append' another 'piece' to the cake, how to do that? 现在我想'追加'另一块'蛋糕',怎么做? (btw i am using FXML from Scene Builder)
(顺便说一下,我在Scene Builder中使用FXML)
(Already tried this but it did not work(shortened version): (已经尝试过这个,但它不起作用(缩短版本):
oldchart = pieChartData.getData();
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(oldchart, new PieChart.Data("GTX 690", 35));
) )
Thanks :D 感谢:D
Just do 做就是了
pieChartData.add(new PieChart.Data("GTX 690", 35));
To remove last added one 删除最后添加的一个
pieChartData.remove(pieChartData.size() - 1);
To clear all 'pieces' 清除所有“碎片”
pieChartData.clear();
Since ,as you noticed, pieChartData is not an java.util.ArrayList
but an javafx.collections.ObservableList
, any changes made to pieChartData collection list will be reflected to the PieChart. 正如您所注意到的,因为pieChartData不是
java.util.ArrayList
而是javafx.collections.ObservableList
,所以对pieChartData集合列表所做的任何更改都将反映到PieChart。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.