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
| import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Date;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.data.category.IntervalCategoryDataset;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;
public class Hello extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void init() {
resize(600, 300);
}
public Hello() {
try
{
IntervalCategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
// create the chart...
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 300));
this.getContentPane().add(chartPanel);
}
catch (Exception e) { System.out.println("Error...."); }
}
public static IntervalCategoryDataset createDataset() {
final TaskSeriesCollection collection = new TaskSeriesCollection();
final TaskSeries s1 = new TaskSeries("Scheduled");
Connection Con = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println("Impossible de charger le pilote jdbc " +e);
}
//connection a la base de données
System.out.println("Connection a la base de données");
try
{
Con = DriverManager.getConnection("jdbc:mysql://localhost:3307/bdreclam","root","1234");
}
catch (SQLException e)
{
System.out.println("Connection à la base de données impossible "+ e);
}
String requete="select * from affectation a join reclamation r where a.idrec=r.idRec;";
try
{
Statement stmt = Con.createStatement();
ResultSet res = stmt.executeQuery(requete);
while (res.next())
{
String ch1=res.getString("Date_deb_des");
String ch2=res.getString("Date_fin_des");
int jj=Integer.parseInt(ch1.substring(0,2));
int mm=Integer.parseInt(ch1.substring(3,5));
int aa=Integer.parseInt(ch1.substring(6,10));
int j=Integer.parseInt(ch2.substring(0,2));
int m=Integer.parseInt(ch2.substring(3,5));
int a=Integer.parseInt(ch2.substring(6,10));
String ch=res.getString("Desc_rec");
for (int k=0;k<ch.length();k++)
{
ch=ch.replace("è", "è");
ch=ch.replace("é", "é");
ch=ch.replace("Ã", "à");
}
System.out.println(res.getString("mat_emp")+" : "+jj+"/"+mm+"/"+aa+" to "+j+"/"+m+"/"+a);
s1.add(new Task(res.getString("mat_emp")+" "+ch,new SimpleTimePeriod(date(jj,mm-1,aa),date(j,m-1,a))));
}
collection.add(s1);
}
catch (SQLException e) {
e.printStackTrace();
}
return collection;
}
private static Date date(final int day, final int month, final int year) {
final Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
final Date result = calendar.getTime();
return result;
}
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createGanttChart(
"Tâches Des Informaticiens", // chart title
"Tâche", // domain axis label
"Date", // range axis label
dataset, // data
true, // include legend
true, // tooltips
true // urls
);
// chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
return chart;
}
} |
Partager