-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarChart.java
68 lines (56 loc) · 2.1 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
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
63
64
65
66
67
68
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.*;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
public class BarChart {
BarChart() {
LinkedHashMap<String,Integer> hm=new LinkedHashMap<String,Integer>();
try
{
Connection con = ObjectFile.getjdbc();
Statement st = con.createStatement();
String query="select District,count(*) as Total from (Patients NATURAL JOIN Prescription natural join Checkup) group by District";
ResultSet result = st.executeQuery(query);
String disease=" ";
int num=0;
while(result.next())
{
disease=result.getString("District");
num=result.getInt("Total");
System.out.println(disease+" "+num);
hm.put(disease,num);
}
con.close();
}
catch(Exception e)
{
}
DefaultCategoryDataset pie=new DefaultCategoryDataset();
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(num,"Count",name);
}
JFreeChart chart=ChartFactory.createBarChart("Affected areas","Place","No of disease",pie,PlotOrientation.VERTICAL,false,true,false);
chart.getPlot().setBackgroundPaint( Color.WHITE );
CategoryPlot p=(CategoryPlot)chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.BLACK);
ChartFrame f=new ChartFrame("Bar Chart",chart);
f.setVisible(true);
f.setBounds(820, 208, 650, 710);
//f.setSize(600,600);
}
public static void main(String []args)
{
new BarChart();
}
}