如何在Javafx中设置饼图位置?



关于我问的最后一个问题(上下文不重要),我正在尝试将CSS样式和PieChart类实现到程序中。但是,我有一个小问题。我似乎无法使用任何方法更改饼图的位置。我不太确定如何从这里开始,我的示例代码如下:

import javafx.scene.Group; //Maybe too many imports, I just use em all
import javafx.scene.Scene; //because I'm lazy
import javafx.scene.chart.PieChart;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class AnimatingDemo extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
//Create PieChart and data for PieChart
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
PieChart pieChart = new PieChart(data);
PieChart.Data one = new PieChart.Data("one", 50.0);
PieChart.Data two = new PieChart.Data("two", 33.0);
PieChart.Data three = new PieChart.Data("three", 17.0);
data.addAll(one, two, three);
//create root group
Group root = new Group();
//set up window
//add nodes to root
root.getChildren().addAll(pieChart);
Scene scene = new Scene(root, 300,500);
stage.setTitle("Testing arc animation");
stage.setScene(scene);luck
stage.show();
}
}

我想知道的是我如何改变饼图的位置,我尝试自己寻找答案几个小时,但没有运气。虽然解决方案可能很简单,但我自己找不到。感谢您的帮助!

你在寻找setLayoutXsetLayoutY吗?在您的情况下,将图表向左移动pieChart.setLayoutX(-100);类似。

让我知道它是否适合您。

最新更新