javafx.scene.chart.PieChart#setLegendVisible ( )源码实例Demo

下面列出了javafx.scene.chart.PieChart#setLegendVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyBox   文件: FxmlControl.java
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;
                    }
                }
            }
        }
    }
}
 
源代码2 项目: ariADDna   文件: CloudSettingsController.java
/**
 * 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");

}
 
源代码3 项目: Maus   文件: StatisticsView.java
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));
}