小编min*_*123的帖子

JavaFX 重复子级饼图

我正在编写一个程序,其中饼图中的按钮单击数据旋转(10-12 点钟方向的切片移动到 12-2 等)。下面的代码(有点)有效,它会旋转,但会吃掉临时切片并产生整段错误。这是我第一次尝试 JavaFX,我不确定如何管理它。

    private BorderPane layout;
    private Scene scene;

    ObservableList<PieChart.Data> pieChartData =
            FXCollections.observableArrayList(
                    new PieChart.Data("Post-production age", 424236),
                    new PieChart.Data("Production age", 1030060),
                    new PieChart.Data("Production age2", 1030060),
                    new PieChart.Data("Production age3", 1030060),
                    new PieChart.Data("Pre-production age", 310319));
    PieChart chart = new PieChart(pieChartData);

    @Override public void start(Stage stage) {
        layout = new BorderPane();
        scene = new Scene(layout,720,480);
        stage.setTitle("People");
        stage.setWidth(500);
        stage.setHeight(500);

        Button button = new Button();
        button.setText("rotate");
        layout.setBottom(button);
        layout.setCenter(chart);
        button.setOnAction(e -> {
            rotate();
        });

        chart.setStartAngle(90);
        chart.setTitle("Economical age groups");
        stage.setScene(scene);
        stage.show();
    }
    public  void rotate(){ …
Run Code Online (Sandbox Code Playgroud)

java javafx

5
推荐指数
1
解决办法
273
查看次数

标签 统计

java ×1

javafx ×1