Advertisement
Guest User

Untitled

a guest
May 27th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package controlador;
  7.  
  8. import java.net.URL;
  9. import java.util.ResourceBundle;
  10. import javafx.application.Platform;
  11. import javafx.collections.ObservableList;
  12. import javafx.fxml.FXML;
  13. import javafx.fxml.Initializable;
  14. import javafx.scene.chart.CategoryAxis;
  15. import javafx.scene.chart.LineChart;
  16. import javafx.scene.chart.NumberAxis;
  17. import javafx.scene.chart.XYChart;
  18. import javafx.scene.control.Slider;
  19. import javafx.scene.layout.AnchorPane;
  20. import modelo.Model;
  21.  
  22. /**
  23. * FXML Controller class
  24. *
  25. * @author Javi
  26. */
  27. public class graph implements Initializable {
  28.  
  29.  
  30. @FXML
  31. private Slider mySlider;
  32.  
  33. private Model model;
  34.  
  35. private ObservableList<Double> datosTWD;
  36.  
  37. private ObservableList<Double> datosTWS;
  38. @FXML
  39. private AnchorPane anchor1;
  40. @FXML
  41. private AnchorPane anchor2;
  42.  
  43. // private ObservableList<> datos;
  44.  
  45. /**
  46. * Initializes the controller class.
  47. */
  48. @Override
  49. public void initialize(URL url, ResourceBundle rb) {
  50. //Crear LineCharts
  51. final NumberAxis xAxis = new NumberAxis();
  52. final NumberAxis yAxis = new NumberAxis();
  53. final LineChart<Number,Number> twdChart =
  54. new LineChart<Number,Number>(xAxis,yAxis);
  55. final NumberAxis xAxis2 = new NumberAxis();
  56. final NumberAxis yAxis2 = new NumberAxis();
  57. final LineChart<Number,Number> twsChart =
  58. new LineChart<Number,Number>(xAxis2,yAxis2);
  59. XYChart.Series series = new XYChart.Series();
  60. XYChart.Series series2 = new XYChart.Series();
  61.  
  62. twdChart.setMaxWidth(240);
  63. twdChart.setMaxHeight(270);
  64. twsChart.setMaxWidth(240);
  65. twsChart.setMaxHeight(270);
  66. //Colocar LineChart en el AnchorPane
  67. anchor1.getChildren().add(twdChart);
  68. anchor2.getChildren().add(twsChart);
  69.  
  70. //Nombre de dades a mostrar en la grafica
  71. int nombreDades;
  72. nombreDades = 60 * (int) mySlider.getValue();
  73.  
  74. model = Model.getInstance();
  75. model.TWDProperty().addListener((observable, oldValue, newValue) -> {
  76. if (datosTWD.size() < nombreDades) {
  77. datosTWD.add((Double) newValue);
  78. } else {
  79. datosTWD.remove(0);
  80. datosTWD.add((Double) newValue);
  81. }
  82. });
  83. model.TWDProperty().addListener((observable, oldValue, newValue) -> {
  84.  
  85. if (datosTWS.size() < nombreDades) {
  86. datosTWS.add((Double) newValue);
  87. }
  88.  
  89. });
  90.  
  91.  
  92.  
  93. series.getData().add(datosTWD);
  94. series2.getData().add(datosTWD);
  95.  
  96. twdChart.getData().add(series);
  97. twsChart.getData().add(series);
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement