-
Notifications
You must be signed in to change notification settings - Fork 1
/
BarChartDemo.java
374 lines (289 loc) · 13.8 KB
/
BarChartDemo.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package wfes;
import Conversion.ProjectCompletion;
import dal.ConnectionDAL;
import dal.TaskDeptDAL;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.RefineryUtilities;
import to.Employee;
import to.Project;
import to.TaskDept;
public class BarChartDemo extends JFrame {
/**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public BarChartDemo(final String title) {
super(title);
// final CategoryDataset dataset = createDataset();
// final JFreeChart chart = createChart(dataset);
// final ChartPanel chartPanel = new ChartPanel(chart);
// chartPanel.setPreferredSize(new Dimension(500, 270));
// setContentPane(chartPanel);
}
/**
* Returns a sample dataset.
*
* @return The dataset.
*/
private CategoryDataset createDataset() {
// row keys...
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";
// column keys...
final String category1 = "Category 1";
final String category2 = "Category 2";
final String category3 = "Category 3";
final String category4 = "Category 4";
final String category5 = "Category 5";
// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, series1, category1);
dataset.addValue(4.0, series1, category2);
dataset.addValue(3.0, series1, category3);
dataset.addValue(5.0, series1, category4);
dataset.addValue(5.0, series1, category5);
dataset.addValue(5.0, series2, category1);
dataset.addValue(7.0, series2, category2);
dataset.addValue(6.0, series2, category3);
dataset.addValue(8.0, series2, category4);
dataset.addValue(4.0, series2, category5);
dataset.addValue(4.0, series3, category1);
dataset.addValue(3.0, series3, category2);
dataset.addValue(2.0, series3, category3);
dataset.addValue(3.0, series3, category4);
dataset.addValue(6.0, series3, category5);
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset,String value,String chartTitle, String category) {
// create the chart...
final JFreeChart chart = ChartFactory.createBarChart(
chartTitle, // chart title
category, // domain axis label
value, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
// set the range axis to display integers only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// disable bar outlines...
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
// set up gradient paints for series...
final GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, Color.lightGray);
final GradientPaint gp1 = new GradientPaint(
0.0f, 0.0f, Color.green,
0.0f, 0.0f, Color.lightGray);
final GradientPaint gp2 = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 0.0f, Color.lightGray);
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
renderer.setSeriesPaint(2, gp2);
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
public void taskcomparisioncall(String chartTitle, Project project) {
final CategoryDataset dataset = taskcomparision(project);
final JFreeChart chart = createChart(dataset,"Completion Percentage","Task Comparision","Tasks");
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset taskcomparision(Project project) {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
List<TaskDept> taskDeptList = new TaskDeptDAL().getTaskDeptDetails();
String series[] = new String[50];
int i = 1;
for (TaskDept taskDeptTemp : taskDeptList) {
if (taskDeptTemp.getProjId().getProjId() == project.getProjId() && taskDeptTemp.getDeptId().getDeptId() == LogIn.localempid.getDeptId().getDeptId()) {
System.out.println("task::" + taskDeptTemp.getTaskId().getTaskId());
double compper;
long remainingtime = new ProjectCompletion().getElapseSec(taskDeptTemp);
if (remainingtime < 0) {
remainingtime = Math.abs(remainingtime);
}
if (remainingtime == 0) {
remainingtime = taskDeptTemp.getDur() * 3600;
}
if (taskDeptTemp.getTdb() == 1) {
compper = 100;
} else {
double dur = taskDeptTemp.getDur() * 3600;
System.out.println("dur::" + dur + "remaining time::" + remainingtime);
compper = ((dur - (double) remainingtime) / dur) * 100;
}
System.out.println("task::" + taskDeptTemp.getTaskId().getTaskId() + "Completion::" + compper);
// result.setValue(taskDeptTemp.getTaskId().getTitle(), compper);
series[i] = taskDeptTemp.getTaskId().getTitle();
// column keys...
final String category1 = "";
// final String category2 = "Urgent";
// create the dataset...
dataset.addValue(compper, series[i], category1);
i++;
}
}
// result.setValue("Mac", 20);
// result.setValue("Windows", 51);
return dataset;
}
public void projectdurationcall(String chartTitle) {
final CategoryDataset dataset = projectduration();
final JFreeChart chart = createChart(dataset,"Days","Project Duration Analysis","Projects");
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset projectduration() {
Connection connection = ConnectionDAL.getConnection();
Statement st;
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
try {
st = connection.createStatement();
String qry1 = "select proj_id,title,end_date,start_date,DATEDIFF(end_date,start_date) as datediff,priority from project";
String series[] = new String[50];
ResultSet rs = st.executeQuery(qry1);
int i = 1;
while (rs.next()) {
series[i] = rs.getString("title");
// column keys...
final String category1 = "Routine";
final String category2 = "Urgent";
// create the dataset...
if (rs.getInt("priority") == 1) {
dataset.addValue(rs.getInt("datediff"), series[i], category1);
} else if (rs.getInt("priority") == 2) {
dataset.addValue(rs.getInt("datediff"), series[i], category2);
}
// dataset.addValue(rs.getInt("datediff"), series[i], category1);
i++;
}
return dataset;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void employeeperformancecall(String chartTitle, Project project) {
final CategoryDataset dataset = employeeperformance(project);
final JFreeChart chart = createChart(dataset,"Employee Performance","Team Performance Analysis","Employee");
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset employeeperformance(Project project) {
try {
Connection connection = new ConnectionDAL().getConnection();
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select avg(er) as avger,td.emp_id,emp.emp_name from taskdept td,task t, employee emp where td.task_id=t.task_id and td.emp_id=emp.emp_id and t.proj_id='"+project.getProjId()+"' and td.dept_id='"+LogIn.localempid.getDeptId().getDeptId()+"' group by emp_id");
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String series[] = new String[50];
int i = 1;
while (rs.next()) {
// result.setValue((Comparable)rs.getString("emp_name"), rs.getDouble("avgkra"));
series[i] = rs.getString("emp_name");
// column keys...
final String category1 = "";
// final String category2 = "Urgent";
// create the dataset...
// if (rs.getInt("priority") == 1) {
// dataset.addValue(rs.getInt("datediff"), series[i], category1);
// } else if (rs.getInt("priority") == 2) {
dataset.addValue(rs.getDouble("avger"), series[i], category1);
// }
// dataset.addValue(rs.getInt("datediff"), series[i], category1);
i++;
}
return dataset;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public void employeeperformanceinallprojectscall(String chartTitle, Employee employee) {
final CategoryDataset dataset = employeeperformanceinallprojects(employee);
final JFreeChart chart = createChart(dataset,"Employee Performance","Employee Performance Analysis","Project");
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset employeeperformanceinallprojects(Employee employee) {
try {
Connection connection = new ConnectionDAL().getConnection();
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select avg(er) as avger,td.emp_id,emp.emp_name,proj.title from taskdept td,task t, employee emp, project proj where td.task_id=t.task_id and td.emp_id=emp.emp_id and t.proj_id=proj.proj_id and td.dept_id='"+LogIn.localempid.getDeptId().getDeptId()+"' and td.emp_id='"+employee.getEmpId()+"' group by t.proj_id");
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String series[] = new String[50];
int i=0;
while (rs.next()) {
// result.setValue((Comparable)rs.getString("proj.title"), rs.getDouble("avgkra"));
series[i] = rs.getString("proj.title");
// column keys...
final String category1 = "";
// final String category2 = "Urgent";
// create the dataset...
// if (rs.getInt("priority") == 1) {
// dataset.addValue(rs.getInt("datediff"), series[i], category1);
// } else if (rs.getInt("priority") == 2) {
dataset.addValue(rs.getDouble("avger"), series[i], category1);
// }
// dataset.addValue(rs.getInt("datediff"), series[i], category1);
i++;
}
return dataset;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}