Example usage for javafx.scene.chart PieChart setMaxSize

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

Introduction

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

Prototype

public void setMaxSize(double maxWidth, double maxHeight) 

Source Link

Document

Convenience method for overriding the region's computed maximum width and height.

Usage

From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java

public void addChartScore() {
    colScore.setCellFactory(new Callback<TableColumn<ReportRow, String>, TableCell<ReportRow, String>>() {
        @Override//from   www.  j ava2  s.  co m
        public TableCell<ReportRow, String> call(TableColumn<ReportRow, String> param) {
            TableCell<ReportRow, String> cell = new TableCell<ReportRow, String>() {
                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!empty && item != null) {

                        Double score = item.indexOf("%") < 0 || item.indexOf("?") >= 0 ? 0
                                : Double.parseDouble(item.substring(0, item.indexOf('%')));

                        ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
                                new PieChart.Data("Correct", score), new PieChart.Data("Error", 100 - score));

                        PieChart chart = new PieChart(pieChartData);
                        chart.setId("pie_chart");
                        chart.setMinSize(22, 22);
                        chart.setMaxSize(22, 22);

                        HBox box = new HBox();
                        box.setSpacing(8);
                        box.setAlignment(Pos.CENTER_LEFT);

                        Label score_label = new Label(item);
                        score_label.setTextFill(Color.LIGHTGRAY);

                        box.getChildren().add(chart);
                        box.getChildren().add(score_label);

                        setGraphic(box);
                    } else {
                        setGraphic(null);
                    }
                }
            };
            return cell;
        }
    });
}