I want to add JFreeChart
to JPanel
and then add JPanel
to JTabbedPane
. I managed to display JFreeChart
on JFrame
, but I want to add JFreeChart
as a 4th tab of JTabbedPane
.
Code to display Chart:
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));
}
Code to add to TabbedPane:
tabStoreTrans.add("chart", new Chart());
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…