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
| String requete = null;
JFreeChart barchart = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:STEG");
SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat ("MM/dd/yyyy");
if ( jDateChooser1.getDate()!=null ) {
if(jDateChooser2.getDate()!=null){
String dateDebut = sdf1.format(jDateChooser1.getDate());
String dateFin=sdf1.format(jDateChooser2.getDate());
if(jTextField12.getText().trim().length()>0 ){
requete="Select Date_Entree, Total FROM `reparation` WHERE UT='"+jTextField12.getText()+"' AND Date_Entree between #"+dateDebut+"# and #"+dateFin+"# ORDER BY Date_Entree";
}else{
requete="Select DISTINCT UT, SUM(Total) as tt FROM `reparation` WHERE Date_Entree between #"+dateDebut+"# and #"+dateFin+"# GROUP BY UT ORDER BY UT";
}
JDBCCategoryDataset dataset=new JDBCCategoryDataset(con,requete);
if(jRadioButton1.isSelected()){
barchart=ChartFactory.createLineChart("Dépense Véhicule(s) "+jTextField12.getText()+" pour la période du "+sdf.format(jDateChooser1.getDate())+" au "+sdf.format(jDateChooser2.getDate()), "Date", "Dépense", dataset, PlotOrientation.VERTICAL, false, true, true);
CategoryPlot plot=barchart.getCategoryPlot();
plot.setBackgroundPaint(Color.ORANGE);
//plot.setRangeGridlinePaint(Color.ORANGE);
}else{
if(jRadioButton2.isSelected()){
barchart=ChartFactory.createBarChart("Dépense Véhicule(s) "+jTextField12.getText()+" pour la période du "+sdf.format(jDateChooser1.getDate())+" au "+sdf.format(jDateChooser2.getDate()), "Date", "Dépense", dataset, PlotOrientation.VERTICAL, false, true, true);
CategoryPlot plot=barchart.getCategoryPlot();
plot.setBackgroundPaint(Color.ORANGE);
}else{
JDBCPieDataset data=new JDBCPieDataset(con,requete);
barchart=ChartFactory.createPieChart("Dépense Véhicule(s) "+jTextField12.getText()+" pour la période du "+sdf.format(jDateChooser1.getDate())+" au "+sdf.format(jDateChooser2.getDate()), data, true, true, true);
Plot plot1=barchart.getPlot();
plot1.setBackgroundPaint(Color.ORANGE);
}
}
}else{
JOptionPane.showMessageDialog(null, "Veuillez donner la date fin de la période!");
}
}else {
if(jDateChooser2.getDate()!=null){
JOptionPane.showMessageDialog(null, "Veuillez donner la date du debut de la période!");
}else{
if(jTextField12.getText().trim().length()==0){
requete="Select DISTINCT UT, SUM(Total) as tt FROM `reparation` WHERE Total IS NOT NULL GROUP BY UT ORDER BY UT";
}else{
requete="Select Date_Entree, Total FROM `reparation` WHERE UT='"+jTextField12.getText().toString()+"' ORDER BY Date_Entree";
}
JDBCCategoryDataset dataset=new JDBCCategoryDataset(con,requete);
if(jRadioButton1.isSelected()){
barchart=ChartFactory.createLineChart("Dépense Véhicule(s) "+jTextField12.getText(), "Date", "Dépense", dataset, PlotOrientation.VERTICAL, false, true, true);
CategoryPlot plot=barchart.getCategoryPlot();
plot.setBackgroundPaint(Color.ORANGE);
//plot.setRangeGridlinePaint(Color.ORANGE);
}else{
if(jRadioButton2.isSelected()){
barchart=ChartFactory.createBarChart("Dépense Véhicule(s) "+jTextField12.getText(), "Date", "Dépense", dataset, PlotOrientation.VERTICAL, false, true, true);
CategoryPlot plot=barchart.getCategoryPlot();
plot.setBackgroundPaint(Color.ORANGE);
}else{
JDBCPieDataset data=new JDBCPieDataset(con,requete);
barchart=ChartFactory.createPieChart("Dépense Véhicule(s) "+jTextField12.getText(), data, true, true, true);
Plot plot1=barchart.getPlot();
plot1.setBackgroundPaint(Color.ORANGE);
}
}
}
}
ChartPanel barpanel=new ChartPanel(barchart);
panelChart.removeAll();
panelChart.add(barpanel);
panelChart.validate();
}catch(Exception e){
e.printStackTrace();
//JOptionPane.showMessageDialog(null, "Veuillez donner la periode!");
//JOptionPane.showMessageDialog(null,e.getMessage() );
//System.out.println( e.getMessage());
} |
Partager