本文介绍了在JPanel中添加一个JFreeChart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有我的Jpanel和我的JFreeChart.如何将此图表添加到JPanel中?

if i have a my Jpanel and a my JFreeChart. How can I add this Chart in to the 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中添加图表?

and now, how can i add chart in my JPanle?

推荐答案

来自旧的 java论坛线程

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

这篇关于在JPanel中添加一个JFreeChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:03