package chartbugs; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Side; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.PieChart; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.animation.Timeline; import javafx.event.ActionEvent; import javafx.event.EventHandler; public class CustomLegend1 extends Application { private void init(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root); primaryStage.setScene(scene); ObservableList pieChartData = FXCollections.observableArrayList(new PieChart.Data("Sun", 20), new PieChart.Data("IBM", 12), new PieChart.Data("HP", 25), new PieChart.Data("Dell", 22), new PieChart.Data("Apple", 30)); final Button customLegend = new Button(); customLegend.setPrefSize(300, 400); customLegend.setOpacity(0.5); final PieChart chart = new PieChart(pieChartData) { { setLegend(customLegend); } }; chart.setLabelsVisible(false); chart.setClockwise(false); chart.setTitle("Title"); chart.setLegendSide(Side.RIGHT); chart.setLabelsVisible(false); Label text = new Label("Text that should be shown below the chart"); Button b = new Button("Remove dataItem"); b.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { System.out.println("Removing item 4"); int i = 6; if (chart.getData() == null) chart.setData(FXCollections.observableArrayList()); chart.getData().add(4, new PieChart.Data("item"+(i++), (int)(Math.random()*50)+10)); chart.getData().remove(4); } }); VBox vBox = new VBox(); vBox.getChildren().addAll(chart, b); root.getChildren().add(vBox); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); } public static void main(String[] args) { launch(args); } }