In relation to the last question I asked (context not important), I'm trying to implement CSS styling and the PieChart class into a program. I have a small problem, however. I can't seem to change the position of the PieChart using any methods. I'm not quite sure how to go from here, my example code is below:
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();
}
}
What I want to know is how I can change the position of the PieChart, I tried looking for the answer myself for a few hours with no luck. Although the solution is likely simple, I can't find it myself. Thanks for the help!
Are you looking for setLayoutX
and setLayoutY
? In your case it will be something like that pieChart.setLayoutX(-100);
to move chart to the left.
Let me know if it works for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.