Example usage for javafx.scene.chart LineChart setCreateSymbols

List of usage examples for javafx.scene.chart LineChart setCreateSymbols

Introduction

In this page you can find the example usage for javafx.scene.chart LineChart setCreateSymbols.

Prototype

public final void setCreateSymbols(boolean value) 

Source Link

Usage

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

/**
 * This method is invoked when the daily balance button has been toggled
 *
 * @param actionEvent//from w  w w .ja  v  a  2  s .c o m
 */
public void dailyBalanceToggled(ActionEvent actionEvent) {
    LocalDateAxis xAxis = new LocalDateAxis();
    NumberAxis yAxis = new NumberAxis();

    final LineChart<LocalDate, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setCreateSymbols(false);

    chartFrame.setCenter(lineChart);

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        xAxis.setLabel("Day of year");
        yAxis.setLabel("Balance in Euro");
        lineChart.setTitle("Balance development day by day");

        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(), yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        xAxis.setLowerBound(period.from());
        xAxis.setUpperBound(period.to());

        Service<Void> service = new Service<Void>() {

            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {

                    @Override
                    protected Void call() throws Exception {
                        Map<Account, List<Transaction>> transactionMap = getTransactions(
                                accountCombo.getValue(), yearCombo.getValue());

                        transactionMap.entrySet().forEach(entry -> {
                            Account account = entry.getKey();
                            List<Transaction> transactionList = entry.getValue();

                            XYChart.Series<LocalDate, Number> series = new XYChart.Series<>();
                            series.setName(format("%s [%s]", account.toPresentableString(),
                                    account.getFormattedBalance()));

                            // sort transactions by operation value descending
                            transactionList.sort((t1, t2) -> t2.getDtOp().compareTo(t1.getDtOp()));
                            account.calculateStartingBalance(transactionList);
                            series.getData()
                                    .add(new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));

                            // sort transactions by operation value ascending
                            transactionList.sort((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()));
                            transactionList.forEach(trx -> {
                                account.calculateCurrentBalance(trx);
                                series.getData().add(
                                        new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));
                            });

                            Platform.runLater(() -> lineChart.getData().add(series));
                        });

                        return null;
                    }
                };
            }
        };
        service.start();
    }
}