Example usage for javafx.scene.chart XYChart.Series getData

List of usage examples for javafx.scene.chart XYChart.Series getData

Introduction

In this page you can find the example usage for javafx.scene.chart XYChart.Series getData.

Prototype

public final ObservableList<Series<X, Y>> getData() 

Source Link

Usage

From source file:View.Visualize.java

private void setupHover(XYChart.Series<String, Number> series) {
    for (final XYChart.Data dt : series.getData()) {

        final Node n = dt.getNode();
        Tooltip tooltip = new Tooltip();
        String toolTipText = "XValue : " + dt.getXValue() + " & YValue : " + dt.getYValue();
        tooltip.setText(toolTipText);/*w  w  w.ja  va  2  s  . c om*/
        tooltip.setStyle(toolTipText);
        Tooltip.install(n, tooltip);

        n.setEffect(null);
        n.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(glow);
            }
        });
        n.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(null);
            }
        });

    }
}

From source file:View.Visualize.java

public void getScatterChartData(Integer nameColumn, Integer valueColumn, Table table, ScatterChart scatterChart,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();/*ww  w  . ja  v a 2s  .c o  m*/
    ObservableList<XYChart.Data> scatterChartData = FXCollections.observableArrayList();

    XYChart.Series series1 = new XYChart.Series();
    if (!newSeries) {
        series1.getData().clear();
        scatterChart.getData().clear();

    }
    scatterChart.setAnimated(false);//bug fix
    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue()))
            .forEach(scatterChartData::add);

    series1.getData().addAll(scatterChartData);
    scatterChart.getData().addAll(series1);
    series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed());
    setupHover(series1);
    addColorChangeOnIndividual(scatterChartData);

}

From source file:View.Visualize.java

public void getLineChartData(Integer nameColumn, Integer valueColumn, Table table, LineChart lineChart,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();/*from   www  .j  a  v a 2 s  .  c  o  m*/
    ObservableList<XYChart.Data> lineChartData = FXCollections.observableArrayList();
    XYChart.Series series1 = new XYChart.Series();
    if (!newSeries) {
        series1.getData().clear();
        lineChart.getData().clear();

    }
    lineChart.setAnimated(false);//bug fix
    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue()))
            .forEach(lineChartData::add);

    series1.getData().addAll(lineChartData);
    lineChart.getData().addAll(series1);
    lineChartSeries.add(series1);
    series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed());
    series1.getNode().setUserData(lineChartSeries.size() - 1);
    addColorChangeOnSeries(series1);
    setupHover(series1);

}

From source file:View.Visualize.java

public void getStackedBarChartData(Integer nameColumn, Integer valueColumn, Table table,
        StackedBarChart stackedBarChart, Boolean newSeries, Boolean rowCounter) {
    data.clear();/*from   w  ww.ja  v  a2  s . c  o  m*/
    ObservableList<XYChart.Data> barChartData = FXCollections.observableArrayList();
    XYChart.Series series1 = new XYChart.Series();

    if (!newSeries) {
        series1.getData().clear();
        stackedBarChart.getData().clear();

    }
    stackedBarChart.setAnimated(false);//bug fix
    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue()))
            .forEach(barChartData::add);

    stackedBarChart.getData().addAll(series1);
    series1.getData().addAll(barChartData);

    series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed());

    setupHover(series1);
    addColorChangeOnIndividual(barChartData);
}

From source file:View.Visualize.java

public void getBarChartData(Integer nameColumn, Integer valueColumn, Table table, BarChart barChart,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();/*from   w  w  w. j a  va 2  s  . co  m*/
    ObservableList<XYChart.Data> barChartData = FXCollections.observableArrayList();
    XYChart.Series series1 = new XYChart.Series();

    if (!newSeries) {
        series1.getData().clear();
        barChart.getData().clear();

    }
    barChart.setAnimated(false);//bug fix
    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue()))
            .forEach(barChartData::add);

    barChart.getData().addAll(series1);
    series1.getData().addAll(barChartData);

    series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed());

    setupHover(series1);
    addColorChangeOnIndividual(barChartData);

}

From source file:View.Visualize.java

public void getAreaChartData(Integer nameColumn, Integer valueColumn, Table table, StackedAreaChart areaChart,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();/*from  w w w  .j  ava2  s  . c  om*/
    ObservableList<XYChart.Data> areaChartData = FXCollections.observableArrayList();
    XYChart.Series series1 = new XYChart.Series();
    if (!newSeries) {
        series1.getData().clear();
        areaChart.getData().clear();
        areaChartSeries.clear();

    }
    areaChart.setAnimated(false);//bug fix
    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue()))
            .forEach(areaChartData::add);

    series1.getData().addAll(areaChartData);

    areaChart.getData().addAll(series1);

    areaChartSeries.add(series1);

    series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed());

    series1.getNode().setUserData(areaChartSeries.size() - 1);
    setupHover(series1);

    addColorChangeOnSeries(series1);

}

From source file:ijfx.ui.utils.ChartUpdater.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    // int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {//from  w  w w  .j  a  v  a2 s .  c  o m
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    Double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .map(v -> v.doubleValue()).sorted()
            //.toArray();
            .toArray(size -> new Double[size]);
    distribution.load(ArrayUtils.toPrimitive(values));

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    //System.out.println(String.format("min = %.0f, max = %.0f, range = %.0f, bin size = %.0f, bin number = %d", min, max, range, binSize, finalBinNumber));

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<XYChart.Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new XYChart.Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {
        serie.getData().addAll(data);
        areaChart.getData().clear();
        areaChart.getData().add(serie);
    });

}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    List<Nacao> nations = new ArrayList<Nacao>(WorldFacadeCounselor.getInstance().getNacoes().values());
    ComparatorFactory.getComparatorNationVictoryPointsSorter(nations);
    xAxis.setCategories(FXCollections.<String>observableList(getNames(nations)));

    //format axis
    yAxis.setTickUnit(200);//from  w w w . j  av  a2s .c  o m
    yAxis.setLabel(labels.getString("PONTOS.VITORIA"));
    //xAxis.setLabel(labels.getString("NACAO"));
    xAxis.setTickMarkVisible(false);

    //Series 1
    XYChart.Series<Number, String> series = new XYChart.Series();
    //series1.setName("XYChart.Series 1");

    for (Nacao nation : WorldFacadeCounselor.getInstance().getNacoes().values()) {
        final XYChart.Data data = new XYChart.Data(nation.getPontosVitoria(), nation.getNome());
        series.getData().add(data);
    }

    //
    final BarChart<Number, String> stackedBarChart = new BarChart<Number, String>(yAxis, xAxis);
    //        stackedBarChart.setTitle(labels.getString("PONTOS.VITORIA"));
    stackedBarChart.getData().addAll(series);
    stackedBarChart.setLegendVisible(false);
    //        stackedBarChart.setCategoryGap(0.2);

    return stackedBarChart;
}

From source file:gui.accessories.GraphPopup.java

private StackedBarChart createStackedBarChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    List<Nacao> nations = new ArrayList<Nacao>(WorldFacadeCounselor.getInstance().getNacoes().values());
    ComparatorFactory.getComparatorNationVictoryPointsSorter(nations);
    xAxis.setCategories(FXCollections.<String>observableList(getNames(nations)));

    //format axis
    yAxis.setTickUnit(200);/*from   w  w  w  .ja va2s  .c om*/
    yAxis.setLabel(labels.getString("PONTOS.VITORIA"));
    //xAxis.setLabel(labels.getString("NACAO"));
    xAxis.setTickMarkVisible(false);

    //Series 1
    XYChart.Series<Number, String> series = new XYChart.Series();
    //series1.setName("XYChart.Series 1");

    for (Nacao nation : WorldFacadeCounselor.getInstance().getNacoes().values()) {
        final XYChart.Data data = new XYChart.Data(nation.getPontosVitoria(), nation.getNome());
        series.getData().add(data);
    }

    //
    final StackedBarChart<Number, String> stackedBarChart = new StackedBarChart<Number, String>(yAxis, xAxis);
    //        stackedBarChart.setTitle(labels.getString("PONTOS.VITORIA"));
    stackedBarChart.getData().addAll(series);
    stackedBarChart.setLegendVisible(false);
    //        stackedBarChart.setCategoryGap(0.2);

    return stackedBarChart;
}

From source file:ijfx.ui.plugin.panel.OverlayPanel.java

protected XYChart.Series<Double, Double> getLineChartSerie(Overlay overlay) {
    System.out.println("Doing things ;-)");
    Double[] valueList = statsService.getValueList(currentDisplay(), overlay);

    ArrayList<Data<Double, Double>> data = new ArrayList<>(valueList.length);
    for (int i = 0; i != valueList.length; i++) {
        data.add(new Data<>(new Double(i), valueList[i]));
    }/*from w  w  w . j a v  a  2 s.c  o  m*/

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    serie.getData().addAll(data);
    return serie;
}