/* * 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 XYChart createChart() { final CategoryAxis xAxis = new CategoryAxis(); final NumberAxis yAxis = new NumberAxis(); // final BubbleChart lc = new BubbleChart(xAxis,yAxis); // final LineChart lc = new LineChart(xAxis,yAxis); // final AreaChart lc = new AreaChart(xAxis,yAxis); final BarChart lc = new BarChart(xAxis,yAxis); // setup chart 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("2010", 150d)); series.getData().add(new XYChart.Data("2011", 30d)); series.getData().add(new XYChart.Data("2012", 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().add(new XYChart.Data("2010", 10d)); chart.getData().get(0).getData().add(new XYChart.Data(Integer.toString(2000 + (int) (Math.random() * 20)), 100 * Math.random())); } }); 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); } }