Reputation: 1022
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).
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)
(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
Upvotes: 0
Views: 2600
Reputation: 49195
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.
Upvotes: 2