Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import javafx.animation.Animation;
  2. import javafx.animation.KeyFrame;
  3. import javafx.animation.Timeline;
  4. import javafx.application.Application;
  5. import javafx.event.ActionEvent;
  6. import javafx.event.EventHandler;
  7. import javafx.scene.Scene;
  8. import javafx.scene.chart.BarChart;
  9. import javafx.scene.chart.CategoryAxis;
  10. import javafx.scene.chart.NumberAxis;
  11. import javafx.scene.chart.XYChart;
  12. import javafx.stage.Stage;
  13. import javafx.util.Duration;
  14.  
  15. public class Main extends Application {
  16.  
  17. final static String itemA = "A";
  18. final static String itemB = "B";
  19. final static String itemC = "F";
  20. @Override
  21. public void start(Stage stage) {
  22. final NumberAxis xAxis = new NumberAxis();
  23. final CategoryAxis yAxis = new CategoryAxis();
  24. final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis);
  25. bc.setTitle("Summary");
  26. xAxis.setLabel("Value");
  27. xAxis.setTickLabelRotation(90);
  28. yAxis.setLabel("Item");
  29.  
  30. XYChart.Series series1 = new XYChart.Series();
  31. series1.setName("2003");
  32. series1.getData().add(new XYChart.Data(2, itemA));
  33. series1.getData().add(new XYChart.Data(20, itemB));
  34. series1.getData().add(new XYChart.Data(10, itemC));
  35.  
  36. XYChart.Series series2 = new XYChart.Series();
  37. series2.setName("2004");
  38. series2.getData().add(new XYChart.Data(50, itemA));
  39. series2.getData().add(new XYChart.Data(41, itemB));
  40. series2.getData().add(new XYChart.Data(45, itemC));
  41.  
  42. XYChart.Series series3 = new XYChart.Series();
  43. series3.setName("2005");
  44. series3.getData().add(new XYChart.Data(45, itemA));
  45. series3.getData().add(new XYChart.Data(44, itemB));
  46. series3.getData().add(new XYChart.Data(18, itemC));
  47.  
  48. Timeline tl = new Timeline();
  49. tl.getKeyFrames().add(new KeyFrame(Duration.millis(500),
  50. new EventHandler<ActionEvent>() {
  51. @Override public void handle(ActionEvent actionEvent) {
  52. for (XYChart.Series<Number, String> series : bc.getData()) {
  53. for (XYChart.Data<Number, String> data : series.getData()) {
  54. data.setXValue(Math.random() * 100);
  55. }
  56. }
  57. }
  58. }));
  59. tl.setCycleCount(Animation.INDEFINITE);
  60. tl.play();
  61.  
  62. Scene scene = new Scene(bc, 800, 600);
  63. bc.getData().addAll(series1, series2, series3);
  64. stage.setScene(scene);
  65. stage.show();
  66. }
  67.  
  68. public static void main(String[] args) {
  69. launch(args);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement