-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarChart.java
30 lines (25 loc) · 1.02 KB
/
BarChart.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import javax.swing.JFrame;
import java.util.List;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.category.*;
class BarChart extends JFrame {
BarChart() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
HibernateDbHandler hdbh = new HibernateDbHandler();
List<Student> studentList = hdbh.getRecords();
for (Student s: studentList) {
dataset.addValue(s.physicsMarks, s.name, "Physics");
dataset.addValue(s.chemistryMarks, s.name, "Chemistry");
dataset.addValue(s.mathsMarks, s.name, "Maths");
}
JFreeChart chart = ChartFactory.createBarChart("Marks of Students", "Subjects", "Marks", dataset, PlotOrientation.VERTICAL, true, false, false);
ChartPanel cp = new ChartPanel(chart);
setContentPane(cp);
setTitle("Marks of Students");
setSize(500, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setVisible(true);
}
}