我想添加JFreeChart
到JPanel
然后添加JPanel
到JTabbedPane
. 我设法在 上显示JFreeChart
,JFrame
但我想添加JFreeChart
为JTabbedPane
.
显示图表的代码:
public class Chart extends javax.swing.JPanel {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JPanel jPanel1 = new JPanel();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(60, "Marks", "Student 1");
dataset.setValue(40, "Marks", "Student 2");
dataset.setValue(90, "Marks", "Student 3");
dataset.setValue(50, "Marks", "Student 4");
dataset.setValue(70, "Marks", "Student 5");
dataset.setValue(30, "Marks", "Student 6");
JFreeChart chart = ChartFactory.createBarChart(
"Student Marks", "Student Name", "Marks", dataset,
PlotOrientation.VERTICAL, false, true, false);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.BLACK);
ChartPanel panel = new ChartPanel(chart);
panel.setDomainZoomable(true);
jPanel1.add(panel, BorderLayout.CENTER);
panel.setPreferredSize(new java.awt.Dimension(500, 270));
}
添加到 TabbedPane 的代码:
tabStoreTrans.add("chart", new Chart());