我创建了JFreeChart并将其放入chartpanel(如建议的那样)。我也将它添加到了jPanel中。我正在使用jFrame。但是运行该程序后看不到我的图表。有人可以帮我吗?

final JFreeChart chart = ChartFactory.createXYLineChart(
        "XY Series Demo",
        "iterácie",
        "%",
        data,
        PlotOrientation.VERTICAL,
        true,
        true,
        false
    );

    final ChartPanel chartPanel = new ChartPanel(chart);
    //chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setDomainZoomable(true);
    chartPanel.setVisible(true);
    jPanel1.add(chartPanel, BorderLayout.CENTER);

最佳答案

(在问题编辑中作答。转换为社区Wiki答案。请参见What is the appropriate action when the answer to a question is added to the question itself?

OP写道:


[解决]我错过了这两个:

jPanel1.setLayout(new java.awt.BorderLayout());
jPanel1.validate();

10-05 22:54