Example usage for javafx.scene.chart PieChart getTitle

List of usage examples for javafx.scene.chart PieChart getTitle

Introduction

In this page you can find the example usage for javafx.scene.chart PieChart getTitle.

Prototype

public final String getTitle() 

Source Link

Usage

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

/**
 * This method is invoked when the "by category" button has been toggled
 *
 * @param actionEvent//from   w  w  w . j  a  va2s.c om
 */
public void byCategoryToggled(ActionEvent actionEvent) {
    final PieChart pieChart = new PieChart();
    pieChart.setTitle("Transaction balance by categories");
    pieChart.setLegendSide(LEFT);
    chartFrame.setCenter(pieChart);
    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(),
                                yearCombo.getValue());
                        if (period.isEmpty()) {
                            return null;
                        }
                        Platform.runLater(() -> pieChart.setTitle(format("%s for transactions from %s until %s",
                                pieChart.getTitle(), period.from().format(DATE_FORMATTER),
                                period.to().format(DATE_FORMATTER))));

                        categoryRepository.findAll().stream()
                                .sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(category -> {
                                    List<Transaction> found = (accountCombo.getValue() == ALL_ACCOUNTS)
                                            ? transactionRepository.findByCategory(category)
                                            : transactionRepository.findByAccountAndCategory(
                                                    accountCombo.getValue(), category);
                                    if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                                        found = found.stream().filter(
                                                trx -> yearCombo.getValue().equals(trx.getDtOp().getYear()))
                                                .sorted((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()))
                                                .collect(toList());
                                    }
                                    List<Transaction> transactions = new ArrayList<>(found.size());
                                    transactions.addAll(found);
                                    Platform.runLater(() -> {
                                        double value = getSum(transactions);
                                        String name = format("%s [%s]", category.getName(),
                                                CurrencyFormat.getInstance().format(value));
                                        PieChart.Data data = new PieChart.Data(name, value);
                                        pieChart.getData().add(data);
                                        data.getNode().addEventHandler(MOUSE_CLICKED,
                                                event -> handleCategoryChartMouseClickEvent(
                                                        (accountCombo.getValue() == ALL_ACCOUNTS) ? null
                                                                : accountCombo.getValue(),
                                                        category, yearCombo.getValue(), event));
                                    });
                                });
                        return null;
                    }
                };
            }
        };
        service.start();
    }
}