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
|
public GraphiqueEtatPatient(){
JPanel p = new JPanel();
// Couleurs des lignes
Color COULEURLIGNE1 = Color.black;
//Color COULEURLIGNE2 = Color.red;
// Creation du graphique
chart = ChartFactory.createTimeSeriesChart("Taux de glycémie des patients","Période","Taux de glycémie",dataSet,true,true,false);
chartPanel = new ChartPanel(chart, true);
// Les dimensions du graphique
Dimension d = new Dimension(350,250);
chartPanel.setMaximumSize(d);
chartPanel.setPreferredSize(d);
chartPanel.setMinimumSize(d);
p.add(chartPanel);
plot = (XYPlot) chart.getPlot();
// On definie une couleur pour les lignes
plot.getRenderer().setSeriesPaint(0,COULEURLIGNE1);
//plot.getRenderer().setSeriesPaint(1,COULEURLIGNE2);
// On definie une couleur de fond pour le graphique
plot.setBackgroundPaint(Color.white);
rangeAxis = (NumberAxis) plot.getRangeAxis();
// On fixe une taille pour l'axe des ordonnées
rangeAxis.setUpperBound(5.0);
add(p);
try {
connection = DriverManager.getConnection(URL + USER + PWD);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT mesure.*, ref, nom FROM mesure, patient WHERE id_patient=ref");
int nbreMesure = 0;
int day, month, year;
// Creation des lignes
TimeSeries mesure_patient = null;
//series_ligne_2 = new TimeSeries("Patient 2", Hour.class);
dataSet.removeAllSeries();
while (rs.next()){
String nom_patient = (String)rs.getObject(10);
System.out.println("nom_patient: "+nom_patient);
mesure_patient = new TimeSeries(nom_patient, Hour.class);
if (rs.getObject(8).equals(rs.getObject(9))){
nbreMesure++;
System.out.println("nbreMesure: "+nbreMesure);
date=(String) rs.getObject(4);
heure=(String) rs.getObject(6);
glycemie=(Double) rs.getObject(5);
hour= Integer.parseInt(heure.substring(0,2));
System.out.println("heur: "+hour);
day = Integer.parseInt(date.substring(0,2));
System.out.println("dat: "+day);
month = Integer.parseInt(date.substring(3,5));
System.out.println("mois: "+month);
year = Integer.parseInt(date.substring(6,10));
System.out.println("annee: "+year);
System.out.println("glycemie: "+glycemie);
mesure_patient.setNotify(true);
mesure_patient.add(new Hour(nbreMesure,day,month,year), glycemie);
}
}
// Ajout des ligne dans le dataset
dataSet.addSeries(mesure_patient);
//dataSet.addSeries(series_ligne_2);
chart.setNotify(true);
chartPanel.setChart(chart);
} catch (SQLException e) {
e.printStackTrace();
}
this.setVisible(true);
}
} |
Partager