Created
May 6, 2021 08:34
-
-
Save Da9el00/9c1e63a5ba8c84e0219bb7e59d7a5bad to your computer and use it in GitHub Desktop.
JavaFX and Scene Builder PieChart controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.beans.binding.Bindings; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ObservableList; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.chart.PieChart; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
public class Controller implements Initializable { | |
@FXML | |
private PieChart pieChart; | |
@Override | |
public void initialize(URL url, ResourceBundle resourceBundle) { | |
ObservableList<PieChart.Data> pieChartData = | |
FXCollections.observableArrayList( | |
new PieChart.Data("Apples", 2), | |
new PieChart.Data("Oranges", 25), | |
new PieChart.Data("Grapes", 50), | |
new PieChart.Data("Melons", 3)); | |
pieChartData.forEach(data -> | |
data.nameProperty().bind( | |
Bindings.concat( | |
data.getName(), " amount: ", data.pieValueProperty() | |
) | |
) | |
); | |
pieChart.getData().addAll(pieChartData); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment