Java Code Examples for javafx.scene.chart.PieChart#setLegendVisible()

The following examples show how to use javafx.scene.chart.PieChart#setLegendVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static void setPieColors(PieChart pie, List<String> palette,
        boolean showLegend) {
    if (pie == null || palette == null
            || pie.getData() == null
            || pie.getData().size() > palette.size()) {
        return;
    }
    for (int i = 0; i < pie.getData().size(); i++) {
        PieChart.Data data = pie.getData().get(i);
        data.getNode().setStyle("-fx-pie-color: " + palette.get(i) + ";");
    }
    pie.setLegendVisible(showLegend);
    if (showLegend) {
        Set<Node> legendItems = pie.lookupAll("Label.chart-legend-item");
        if (legendItems.isEmpty()) {
            return;
        }
        for (Node legendItem : legendItems) {
            Label legendLabel = (Label) legendItem;
            Node legend = legendLabel.getGraphic();
            if (legend != null) {
                for (int i = 0; i < pie.getData().size(); i++) {
                    String name = pie.getData().get(i).getName();
                    if (name.equals(legendLabel.getText())) {
                        legend.setStyle("-fx-background-color: " + palette.get(i));
                        break;
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: CloudSettingsController.java    From ariADDna with Apache License 2.0 6 votes vote down vote up
/**
 * Generate pipe chart
 */
private void initChart() {
    PieChart.Data available = new PieChart.Data("Available", 13);
    PieChart.Data used = new PieChart.Data("Used", 25);
    PieChart.Data empty = new PieChart.Data("Empty", 10);

    ObservableList<PieChart.Data> pieChartData =
            FXCollections.observableArrayList(available, used, empty);
    final PieChart chart = new PieChart(pieChartData);
    chart.setTitle("");
    chart.setPrefSize(350, 350);
    chart.setLegendVisible(false);
    chart.setStyle("-fx-background-color: none");
    pieChartPane.getChildren().add(chart);

    available.getNode().setStyle("-fx-background-color: #55c4fe");
    used.getNode().setStyle("-fx-background-color: #008287");
    empty.getNode().setStyle("-fx-background-color: #219297");

}
 
Example 3
Source File: StatisticsView.java    From Maus with GNU General Public License v3.0 6 votes vote down vote up
private HBox getSystemPanel() {
    ObservableList<PieChart.Data> pieChartData =
            FXCollections.observableArrayList();
    CONNECTIONS.forEach((string, clientObject) -> {
        if (clientObject.getSYSTEM_OS() != null) {
            if (operatingSystems.containsKey(clientObject.getSYSTEM_OS())) {
                operatingSystems.put(clientObject.getSYSTEM_OS(), operatingSystems.get(clientObject.getSYSTEM_OS()) + 1);
            } else {
                operatingSystems.put(clientObject.getSYSTEM_OS(), 1);
            }
        }
    });
    operatingSystems.forEach((string, integer) -> {
        pieChartData.add(new PieChart.Data(string, CONNECTIONS.size() / integer));
    });
    final PieChart chart = new PieChart(pieChartData);
    chart.setLegendVisible(false);
    chart.setTitle("Operating Systems");
    chart.setMaxSize(300, 300);
    return Styler.hContainer(Styler.vContainer(10, chart));
}