/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.chart.*; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * * @author akouznet */ public class Bug extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } private XYChart chart; private VBox root; protected LineChart createChart() { final NumberAxis xAxis = new NumberAxis(); final NumberAxis yAxis = new NumberAxis(); final LineChart lc = new LineChart(xAxis,yAxis); // setup chart lc.setTitle("Basic LineChart"); xAxis.setLabel("X Axis"); yAxis.setLabel("Y Axis"); // add starting data XYChart.Series series = new XYChart.Series(); series.setName("Data Series 1"); series.getData().add(new XYChart.Data(20d, 150d)); series.getData().add(new XYChart.Data(70d, 30d)); series.getData().add(new XYChart.Data(170d, 62d)); lc.getData().add(series); chart = lc; return lc; } @Override public void start(Stage primaryStage) { Button animate = new Button("Animate"); animate.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { chart.getData().get(0).getData().remove(0); } }); Button revert = new Button("Revert"); revert.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { root.getChildren().set(1, createChart()); } }); HBox buttonsHBox = new HBox(); buttonsHBox.getChildren().setAll(animate, revert); root = new VBox(); root.getChildren().setAll(buttonsHBox, createChart()); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); // ScenicView.show(root); } }