【发布时间】:2017-10-23 10:56:56
【问题描述】:
我对编程还很陌生,对于学校来说,我必须创建一个包含一定数量课程的程序。目前一切进展顺利,但我被困在数据的图形输出上。该程序是一个费用计算器。它是一个分为 6 个 JPanel 的框架。其中一个应该是我创建的饼图。饼图有效,但不会显示在我的框架中。所以我被困在如何将正确的内容调用到面板上。我要添加饼图的面板的代码是:
class CenterPaneel extends JPanel{
private static final long serialVersionUID = -835526987955952967L;
public CenterPaneel(){
setLayout( new GridLayout(2,3,10,10));
add( new Catagorie1Paneel() ); add( new Catagorie3Paneel() ); add( new SamenvattingPaneel() );
add( new Catagorie2Paneel() ); add( new Catagorie4Paneel() ); add( new DataPaneel());
}
饼图的代码是:
class DataPaneel extends JPanel{
private static final long serialVersionUID = -2980457707385367851L;
private final ObservableList<PieChart.Data> details = FXCollections.observableArrayList();
private BorderPane root;
private PieChart pieChart;
public void start(Stage primaryStage) {
primaryStage.setTitle("test");
details.addAll(new PieChart.Data("test1", 25),
new PieChart.Data("test 2", 25),
new PieChart.Data("test 3", 25),
new PieChart.Data("test 4", 25)
);
root = new BorderPane();
Scene scene = new Scene(root,600,500);
pieChart = new PieChart();
pieChart.setData(details);
pieChart.setTitle("test");
pieChart.setLegendSide(Side.BOTTOM);
pieChart.setLabelsVisible(true);
primaryStage.setScene(scene);
primaryStage.show();
}
}
到目前为止的代码输出是:
如果有人可以帮助我,我会很高兴:)
提前致谢
【问题讨论】:
-
好吧,你可以看看 JFreeCharts 之类的东西,或者你可以看看 2D Graphics tutorial
标签: java swing jpanel pie-chart