Example usage for javafx.scene.chart PieChart.Data PieChart.Data

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

Introduction

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

Prototype

public Data(java.lang.String name, double value) 

Source Link

Document

Constructs a PieChart.Data object with the given name and value.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Imported Fruits");
    stage.setWidth(500);/*from ww  w .  ja  v a  2s.co m*/
    stage.setHeight(500);

    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
            new PieChart.Data("Grapefruit", 13), new PieChart.Data("Oranges", 25),
            new PieChart.Data("Plums", 10), new PieChart.Data("Pears", 22), new PieChart.Data("Apples", 30));

    final PieChart chart = new PieChart(pieChartData);
    chart.setTitle("Imported Fruits");
    final Label caption = new Label("");
    caption.setTextFill(Color.DARKORANGE);
    caption.setStyle("-fx-font: 24 arial;");

    for (final PieChart.Data data : chart.getData()) {
        data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                caption.setTranslateX(e.getSceneX());
                caption.setTranslateY(e.getSceneY());
                caption.setText(String.valueOf(data.getPieValue()) + "%");
            }
        });
    }

    ((Group) scene.getRoot()).getChildren().addAll(chart, caption);
    stage.setScene(scene);
    //scene.getStylesheets().add("piechartsample/Chart.css");
    stage.show();
}

From source file:org.opendolphin.mvndemo.clientlazy.DemoController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    //Sending Command and get list with column names in the response.
    DemoApp.clientDolphin.send(CMD_GETLAZYCOLUMNS, new OnFinishedHandlerAdapter() {
        @Override/*  w ww  .  j a v a2s  .c  o m*/
        public void onFinishedData(List<Map> data) {
            if (data != null && data.size() == 1) {
                //Create lazy table with colums from the response
                createTableLazy(data);
            }
        }

    });
    //
    // when starting, first fill the table with pm ids
    DemoApp.clientDolphin.send(CMD_LAZYTABLELOAD, new OnFinishedHandlerAdapter() {
        @Override
        public void onFinishedData(List<Map> data) {
            for (Map map : data) {
                lazyRows.addAll(map.values());
            }
            unused.setValue(lazyRows.size());
        }
    });
    //
    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
    PieChart.Data usedData = new PieChart.Data("Used", 23);
    usedData.pieValueProperty().bind(used);
    pieChartData.add(usedData);
    PieChart.Data unusedData = new PieChart.Data("unused", 100 - 23);
    unusedData.pieValueProperty().bind(unused);
    pieChartData.add(unusedData);
    pieLazyUse.setData(pieChartData);
    //
    used.addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            pieLabel.setText(String.format("Zeilen: %d / %d ", newValue, lazyRows.size()));
        }
    });
    //
    DemoApp.clientDolphin.getClientConnector().setUiThreadHandler(new JavaFXUiThreadHandler());
}

From source file:de.ifsr.adam.ImageGenerator.java

/**
 * Creates the data list for a pie chart.
 *
 * @param result The result JSONObject you wish to transform
 * @param answerType The answer type JSONObject of the question
 * @return/*from  w  w  w  .  ja  v a2 s .  c o m*/
 */
private ObservableList<PieChart.Data> generateDataPieChart(JSONObject result, JSONObject answerType) {
    ArrayList<PieChart.Data> list = new ArrayList<>();

    try {
        JSONObject answers;
        String[] fieldNames;

        try {
            answers = answerType.getJSONObject("answers");
            fieldNames = JSONObject.getNames(result);
        } catch (NullPointerException e) {
            log.error("Missing JSONObject in result:" + result + " answerType: " + answerType);
            log.debug("", e);
            return FXCollections.observableArrayList(list);
        }

        for (int i = 1; i < fieldNames.length; i++) {//i is 1 at the start to ignore the empty String result in the answers
            String answer = answers.getString(fieldNames[i]);
            Integer value = result.getInt(fieldNames[i]);
            list.add(new PieChart.Data(answer, value));
        }
    } catch (JSONException e) {
        log.error(e);
    }

    return FXCollections.observableArrayList(list);
}

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 ww  .j a v a 2s .co m
 */
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();
    }
}

From source file:UI.MainStageController.java

/**
 * creates the data for the analysis pane and displays it
 * data created includes://from   w  ww .j  a v  a2  s.c om
 * highest positive/negative correlations
 * average counts
 */
private void displayAnalysisTextsAndGraphs() {
    //Display node with highest frequency
    double highestFrequency = AnalysisData.getHighestFrequency();
    TaxonNode nodeWithHighestFrequency = AnalysisData.getNodeWithHighestFrequency();
    dataStatText.setText("Highest Frequency:\n" + nodeWithHighestFrequency.getName() + " ("
            + String.format("%.3f", highestFrequency) + ")\n");

    //Display nodes with highest positive/negative correlation
    RealMatrix correlationMatrix = AnalysisData.getCorrelationMatrix();
    int[] highestPositiveCorrelationCoordinates = AnalysisData.getHighestPositiveCorrelationCoordinates();
    int[] highestNegativeCorrelationCoordinates = AnalysisData.getHighestNegativeCorrelationCoordinates();
    LinkedList<TaxonNode> taxonList = SampleComparison.getUnifiedTaxonList(LoadedData.getSamplesToAnalyze(),
            AnalysisData.getLevelOfAnalysis());
    TaxonNode hPCNode1 = taxonList.get(highestPositiveCorrelationCoordinates[0]);
    TaxonNode hPCNode2 = taxonList.get(highestPositiveCorrelationCoordinates[1]);
    TaxonNode hNCNode1 = taxonList.get(highestNegativeCorrelationCoordinates[0]);
    TaxonNode hNCNode2 = taxonList.get(highestNegativeCorrelationCoordinates[1]);

    dataStatText.setText(dataStatText.getText() + "\nHighest Positive Correlation:\n" + hPCNode1.getName()
            + " - " + hPCNode2.getName() + " ("
            + String.format("%.3f", correlationMatrix.getEntry(highestPositiveCorrelationCoordinates[0],
                    highestPositiveCorrelationCoordinates[1]))
            + ")\n");
    dataStatText.setText(dataStatText.getText() + "\nHighest Negative Correlation:\n" + hNCNode1.getName()
            + " - " + hNCNode2.getName() + " ("
            + String.format("%.3f", correlationMatrix.getEntry(highestNegativeCorrelationCoordinates[0],
                    highestNegativeCorrelationCoordinates[1]))
            + ")");

    //Generate Data for the pie chart
    frequencyChart.getData().clear();
    HashMap<TaxonNode, Double> averageCounts = SampleComparison
            .calcAverageCounts(LoadedData.getSamplesToAnalyze(), AnalysisData.getLevelOfAnalysis());
    for (TaxonNode taxonNode : averageCounts.keySet()) {
        PieChart.Data data = new PieChart.Data(taxonNode.getName(), averageCounts.get(taxonNode));
        frequencyChart.getData().add(data);
    }

    analysisPane.setVisible(true);
}