/**
   * Método para pintar la gráfica
   *
   * @param min
   * @param max
   * @param grado
   */
  private void pintarGrafica(int min, int max, int grado) {

    // Creamos un ObservableList para guardar los puntos que pintaremos en la gráfica
    ObservableList<XYChart.Series<Double, Double>> lineChartData =
        FXCollections.observableArrayList();

    // Instanciamos un punto a pintar
    LineChart.Series<Double, Double> series = new LineChart.Series<Double, Double>();

    // Imprimimos la función que vamos a pintar como etiqueta
    series.setName("f(x^" + grado + ")");

    // obtenemos los puntos a pintar. Daros cuenta que los puntos a pintar estan definidos
    // por el valor de 'x' y el resultado de 'f(x)', siendo f(x)=Math.pow(x, grado) = x^grado
    for (double i = min; i < max; i = i + 0.1) {
      series.getData().add(new XYChart.Data<Double, Double>(i, Math.pow(i, grado)));
    }

    // Guardamos todos los puntos de la función que hemos obtenido
    lineChartData.add(series);

    // Si No quereis que se pinten los puntos, poner a false
    graph.setCreateSymbols(true);

    // Ponemos los puntos en la gráfica
    graph.setData(lineChartData);
    graph.createSymbolsProperty();
  }
예제 #2
0
  static LineChart<String, Number> initializeChart(
      String title, boolean showPercentages, VBox container) {

    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    if (showPercentages) {
      yAxis.setLabel("%");
    } else {
      yAxis.setLabel("€");
    }
    yAxis.setForceZeroInRange(false);
    yAxis.setSide(Side.RIGHT);

    final LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setPrefHeight(700);
    lineChart.setTitle(title);
    lineChart.setTitleSide(Side.LEFT);
    lineChart.setCreateSymbols(false);
    lineChart.setVerticalGridLinesVisible(false);
    lineChart.setHorizontalGridLinesVisible(true);

    XYChart.Series seriesMax = new XYChart.Series();
    XYChart.Series seriesMin = new XYChart.Series();
    XYChart.Series seriesAverage = new XYChart.Series();
    lineChart.getData().addAll(seriesMax, seriesMin, seriesAverage);

    lineChart.setLegendVisible(true);
    lineChart.setLegendSide(Side.RIGHT);

    container.getChildren().add(lineChart);

    lineChart.getStylesheets().add("charts.css");

    return lineChart;
  }
  @Override
  public void start(Stage stage) {

    Parameters parameters = getParameters();
    List<String> rawArguments = parameters.getRaw();

    List<String> file_paths = new LinkedList<String>();

    int size = rawArguments.size(); // un solo file / argomento in realtà

    for (int i = 0; i < size; i++) {
      String path_data_file = rawArguments.get(i);
      System.out.println(" * data file n." + (i + 1) + " : " + path_data_file);
      file_paths.add(path_data_file);
    }

    stage.setTitle("Cpu during joining");

    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();

    xAxis.setLabel("time");
    // xAxis.setTickUnit(10);

    yAxis.setLabel("CPU %");
    yAxis.setTickUnit(2);

    final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

    lineChart.setTitle("CPU during Joining and Cleanups");
    lineChart.setCreateSymbols(false);

    // add_line_to_chart(lineChart, file_paths.get(0), "from 3 to 4 nodes", 3, 80000);
    // add_line_to_chart(lineChart, file_paths.get(0), "from 4 to 5 nodes", 4, 95000);
    add_line_to_chart(lineChart, file_paths.get(0), "from 5 to 6 nodes", 5, 112000);

    Scene scene = new Scene(lineChart, 800, 600);

    stage.setScene(scene);
    stage.show();
  }
예제 #4
0
  protected TabbedInspector buildInspector() {

    // create the network
    network = new ExchangeNetwork(getGoodType());

    // if there is no GUI, forget about it
    Preconditions.checkState(MacroII.hasGUI()); // can't be called otherwise!

    TabbedInspector toReturn = new TabbedInspector(true);
    toReturn.setName(toString() + " inspector");

    /**
     * ******************************************* Prices ******************************************
     */

    // switching to JavaFX for fun and profit
    // set up the chart
    panel = new JFXPanel();

    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Day");
    yAxis.setLabel("Price");
    final LineChart<Number, Number> priceChart = new LineChart<>(xAxis, yAxis);
    priceChart.setAnimated(true);

    // set up the series
    priceSeries = new XYChart.Series<>();
    priceSeries.setName("LastClosingPrice");
    // now make the price update whenever data updates!
    // use steppable to update

    priceChart.getData().add(priceSeries);

    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            panel.setScene(new Scene(priceChart));
          }
        });
    // we are going to add the new JPanel IN the new inspector
    closingPriceInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    closingPriceInspector.setVolatile(true);
    closingPriceInspector.setLayout(new BorderLayout()); // this centers it
    closingPriceInspector.add(panel);

    toReturn.addInspector(closingPriceInspector, "Closing price");

    /**
     * ******************************************* VOLUME ******************************************
     */

    // switching to JavaFX for fun and profit
    // set up the chart
    final JFXPanel panel2 = new JFXPanel();

    xAxis = new NumberAxis();
    yAxis = new NumberAxis();
    xAxis.setLabel("Day");
    yAxis.setLabel("Volume");
    final LineChart<Number, Number> volumeChart = new LineChart<>(xAxis, yAxis);
    volumeChart.setAnimated(true);
    volumeChart.setCreateSymbols(false);
    // set up the series
    volumeSeries = new XYChart.Series<Number, Number>();
    volumeSeries.setName("Daily Volume Traded");

    volumeChart.getData().add(volumeSeries);
    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            panel2.setScene(new Scene(volumeChart));
          }
        });
    // we are going to add the new JPanel IN the new inspector
    Inspector closingVolumeInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    closingVolumeInspector.setVolatile(true);
    closingVolumeInspector.setLayout(new BorderLayout()); // this centers it
    closingVolumeInspector.add(panel2);

    toReturn.addInspector(closingVolumeInspector, "Volume");

    /**
     * ******************************************* TIMELINE
     * ******************************************
     */
    // todo logtodo

    /**
     * ************************************************* Network
     * *************************************************
     */
    Inspector networkInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    networkInspector.setLayout(new BorderLayout());
    // add the visualization
    networkInspector.add(network.getVisualization());
    toReturn.addInspector(networkInspector, "Network");

    return toReturn;
  }