Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package controlador;
- import java.net.URL;
- import java.util.ResourceBundle;
- import javafx.application.Platform;
- import javafx.collections.ObservableList;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.chart.CategoryAxis;
- import javafx.scene.chart.LineChart;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.XYChart;
- import javafx.scene.control.Slider;
- import javafx.scene.layout.AnchorPane;
- import modelo.Model;
- /**
- * FXML Controller class
- *
- * @author Javi
- */
- public class graph implements Initializable {
- @FXML
- private Slider mySlider;
- private Model model;
- private ObservableList<Double> datosTWD;
- private ObservableList<Double> datosTWS;
- @FXML
- private AnchorPane anchor1;
- @FXML
- private AnchorPane anchor2;
- // private ObservableList<> datos;
- /**
- * Initializes the controller class.
- */
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- //Crear LineCharts
- final NumberAxis xAxis = new NumberAxis();
- final NumberAxis yAxis = new NumberAxis();
- final LineChart<Number,Number> twdChart =
- new LineChart<Number,Number>(xAxis,yAxis);
- final NumberAxis xAxis2 = new NumberAxis();
- final NumberAxis yAxis2 = new NumberAxis();
- final LineChart<Number,Number> twsChart =
- new LineChart<Number,Number>(xAxis2,yAxis2);
- XYChart.Series series = new XYChart.Series();
- XYChart.Series series2 = new XYChart.Series();
- twdChart.setMaxWidth(240);
- twdChart.setMaxHeight(270);
- twsChart.setMaxWidth(240);
- twsChart.setMaxHeight(270);
- //Colocar LineChart en el AnchorPane
- anchor1.getChildren().add(twdChart);
- anchor2.getChildren().add(twsChart);
- //Nombre de dades a mostrar en la grafica
- int nombreDades;
- nombreDades = 60 * (int) mySlider.getValue();
- model = Model.getInstance();
- model.TWDProperty().addListener((observable, oldValue, newValue) -> {
- if (datosTWD.size() < nombreDades) {
- datosTWD.add((Double) newValue);
- } else {
- datosTWD.remove(0);
- datosTWD.add((Double) newValue);
- }
- });
- model.TWDProperty().addListener((observable, oldValue, newValue) -> {
- if (datosTWS.size() < nombreDades) {
- datosTWS.add((Double) newValue);
- }
- });
- series.getData().add(datosTWD);
- series2.getData().add(datosTWD);
- twdChart.getData().add(series);
- twsChart.getData().add(series);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement