-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPie_Chart.java
More file actions
62 lines (52 loc) · 1.77 KB
/
Pie_Chart.java
File metadata and controls
62 lines (52 loc) · 1.77 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package bootathonfinal;
import java.awt.*;
import java.sql.DriverManager;
import java.util.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import java.sql.*;
public class Pie_Chart {
public Pie_Chart() {
LinkedHashMap<String,Integer> hm=new LinkedHashMap<String,Integer>();
System.out.println("hi");
try
{
Connection con = ObjectFile.getjdbc();
Statement st = con.createStatement();
String query="select disease,count(*) as Total from Prescription group by disease";
ResultSet result = st.executeQuery(query);
String disease=" ";
int num=0;
while(result.next())
{
disease=result.getString("disease");
num=result.getInt("Total");
hm.put(disease,num);
}
con.close();
}
catch(Exception e)
{
}
DefaultPieDataset pie=new DefaultPieDataset();
Set<Map.Entry<String,Integer>>map=hm.entrySet();
for(Map.Entry<String,Integer>matp :map)
{
String name=matp.getKey();
int num=matp.getValue();
pie.setValue(name ,num);
}
JFreeChart chart=ChartFactory.createPieChart("Pie chart",pie,true,true,true);
chart.getPlot().setBackgroundPaint( Color.WHITE );
PiePlot p=(PiePlot)chart.getPlot();
ChartFrame f=new ChartFrame("Pie Chart",chart);
f.setVisible(true);
f.setLocationRelativeTo(null);
f.setBounds(820, 208, 650, 710);
f.setLayout(null);
}
public static void main(String[]args) {
new Pie_Chart();
}
}