class StatDisplayUtils {

    public static LineChart<String, Number> buildLineChart(Stats stats, final Region root) {

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

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

        // defining a series
        Series<String, Number> series = new Series<>();
        Series<String, Number> average = new Series<>();
        Series<String, Number> sdp = new Series<>();
        Series<String, Number> sdm = new Series<>();
        // populating the series with data

        final List<Long> shots;
        if (stats instanceof ShootGamesStats) {
            shots = stats.getSortedDurationsBetweenGoals();
        } else {
            shots = stats.getOriginalDurationsBetweenGoals();
        }

        double sd = stats.computeRoundsDurationStandardDeviation();

        String xValue = "0";

        average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration()));
        sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd));
        sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd));

        int i = 1;

        for (Long duration : shots) {
            xValue = Integer.toString(i);
            series.getData().add(new Data<>(xValue, duration));
            average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration()));

            sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd));
            sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd));
            i++;
        }

        xValue = Integer.toString(i);
        average.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration()));
        sdp.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() + sd));
        sdm.getData().add(new Data<>(xValue, stats.computeRoundsDurationAverageDuration() - sd));

        lineChart.setCreateSymbols(false);

        lineChart.getData().add(average);
        lineChart.getData().add(sdp);
        lineChart.getData().add(sdm);
        lineChart.getData().add(series);

        series.getNode().setStyle("-fx-stroke-width: 3; -fx-stroke: red; -fx-stroke-dash-offset:5;");
        average.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: lightgreen;");
        sdp.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: grey;");
        sdm.getNode().setStyle("-fx-stroke-width: 1; -fx-stroke: grey;");

        EventHandler<Event> openLineChartEvent = createZoomInLineChartEventHandler(lineChart, root);

        lineChart.addEventHandler(MouseEvent.MOUSE_CLICKED, openLineChartEvent);

        lineChart.setLegendVisible(false);

        root.widthProperty().addListener((observable, oldValue, newValue) -> lineChart.setMaxWidth(newValue.doubleValue() * 0.4));
        root.heightProperty().addListener((observable, oldValue, newValue) -> lineChart.setMaxHeight(newValue.doubleValue() * 0.4));
        lineChart.setMaxWidth(root.getWidth() * 0.4);
        lineChart.setMaxHeight(root.getHeight() * 0.4);

        return lineChart;
    }

}