java – 将JFreeChart添加到JPanel中

前端之家收集整理的这篇文章主要介绍了java – 将JFreeChart添加到JPanel中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有一个我的Jpanel和一个我的JFreeChart.如何将此图表添加到JPanel?
XYSeries series = new XYSeries("XYGraph");
   series.add(1,1);
   series.add(1,2);
   series.add(2,1);
   series.add(3,9);
   series.add(4,10);

// Add the series to your data set
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(series);

// Generate the graph
   JFreeChart chart = ChartFactory.createXYLineChart(
   "XY Chart",// Title
   "x-axis",// x-axis Label
   "y-axis",// y-axis Label
   dataset,// Dataset
   PlotOrientation.VERTICAL,// Plot Orientation
   true,// Show Legend
   true,// Use tooltips
   false // Configure chart to generate URLs?
);

现在我怎么可以在我的JPanle中添加图表?

解决方法

从旧 java forums thread
JPanel jPanel1 = new JPanel();
jPanel1.setLayout(new java.awt.BorderLayout());
 ..
ChartPanel CP = new ChartPanel(chart);
.. 
jPanel1.add(CP,BorderLayout.CENTER);
jPanel1.validate();

猜你在找的Java相关文章