import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.PieChart; import javafx.scene.control.Label; import javafx.stage.Stage; import javafx.scene.text.Font; /** * * @web http://java-buddy.blogspot.com/ */ public class JavaFXApplication61 extends Application { Label label; /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("java-buddy.blogspot.com"); Group root = new Group(); ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data("January", 100), new PieChart.Data("February", 200) ); final PieChart pieChart = new PieChart(pieChartData); pieChart.setTitle("PieChart"); label = new Label(""); label.setFont(new Font(14.0)); //add event handler for(final PieChart.Data data : pieChart.getData()){ data.getNode().addEventHandler( javafx.scene.input.MouseEvent.MOUSE_ENTERED, new EventHandler() { @Override public void handle(javafx.scene.input.MouseEvent mouseEvent) { String name = data.getName(); double value = data.getPieValue(); label.setText(name + " : " + String.valueOf(value)); } }); data.getNode().addEventHandler( javafx.scene.input.MouseEvent.MOUSE_EXITED, new EventHandler() { @Override public void handle(javafx.scene.input.MouseEvent mouseEvent) { label.setText(""); } }); } root.getChildren().add(pieChart); root.getChildren().add(label); primaryStage.setScene(new Scene(root, 500, 400)); primaryStage.show(); } }