package bugsfiling; import javafx.application.Application; import javafx.builders.CategoryAxisBuilder; import javafx.builders.NumberAxisBuilder; import javafx.builders.StackPaneBuilder; import javafx.collections.FXCollections; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.chart.BarChart; import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class BarChartRefreshData extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { final BarChart barChart = new BarChart( new CategoryAxisBuilder() .build(), new NumberAxisBuilder() .build()); // barChart.setAnimated(false); barChart.setOnMouseClicked(new EventHandler() { public void handle(MouseEvent event) { barChart.setData(FXCollections.observableArrayList( new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 10))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 20))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 1))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 50))))); } }); // This produces bars that have no labels on category axis: barChart.setData(FXCollections.observableArrayList( new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 10))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 20))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 1))), new BarChart.Series(FXCollections.observableArrayList(new BarChart.Data("A", 50))))); StackPane root = new StackPaneBuilder() .children(barChart) .build(); Scene scene = new Scene(root); stage.setScene(scene); stage.setVisible(true); } }