@Override
public void start(Stage stage) throws Exception {
PieChart pie = new PieChart();
pie.setData(getChart());
StackPane pane = new StackPane();
Scene scene = new Scene(pane);
stage.setScene(scene);
pane.getChildren().addAll(pie);
stage.show();
}
private ObservableList<PieChart.Data> getChart() {
ObservableList<PieChart.Data> list = FXCollections.observableArrayList();
list.addAll(new PieChart.Data("java",20), new PieChart.Data("c",20),
new PieChart.Data("C++",20));
return list;
}
我希望此图表显示在场景构建器上。怎么可能.. ??
答案 0 :(得分:0)
在SceneBuilder中,从菜单中:
File | Open
View | Show Sample Data
pie.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<StackPane id="StackPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<PieChart id="PieChart" prefHeight="-1.0" prefWidth="-1.0" />
</children>
</StackPane>