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
|
package vue;
import ...;
@SuppressWarnings("serial")
public class GraphiqueEtatPatient extends JPanel{
private Connection connection;
private final String URL = "jdbc:derby://localhost:1527/DiabetoMedical";
private final String USER = ";user=user";
private final String PWD = ";password=user";
private double glycemie=1.80;
NumberAxis rangeAxis;
ChartPanel chartPanel;
JPanel p;
JFreeChart chart;
RegularTimePeriod rtp;
TimeSeriesCollection dataSet = new TimeSeriesCollection();
XYPlot plot;
Fenetre fen;
int hour = 0;
int nbreMesure = 0;
private String date;
// private Double mixtard30, axtrapide;
public GraphiqueEtatPatient(){
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);
System.out.println("ici");
try {
connection = DriverManager.getConnection(URL + USER + PWD);
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();
String nom_patient="";
Statement stm = connection.createStatement();
ResultSet res = stm.executeQuery("SELECT count(ref) FROM patient");
int count = 0;
while (res.next()){
count= res.getInt(1);
}
System.out.println("count: "+count);
int r = 1;
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT mesure.*, ref, nom FROM mesure, patient WHERE id_patient=ref");
while (rs.next()){
System.out.println("r"+r);
//mesure_patient = new TimeSeries(nom_patient, Hour.class);
if (rs.getInt(8)==r){
nom_patient = (String)rs.getObject(9);
System.out.println("nom_patient: "+nom_patient);
int id_patient = (int)rs.getInt(7);
System.out.println("id_patient: "+id_patient);
nbreMesure++;
System.out.println("nbreMesure: "+nbreMesure);
date=(String) rs.getObject(4);
glycemie=(Double) rs.getObject(5);
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);
new TimeSeries(nom_patient, Hour.class).setNotify(true);
new TimeSeries(nom_patient, Hour.class).add(new Hour(nbreMesure,day,month,year), glycemie);
}else{
// Ajout des ligne dans le dataset
dataSet.addSeries(new TimeSeries(nom_patient, Hour.class));
//dataSet.addSeries(series_ligne_2);
r++;
}
}
// Ajout des ligne dans le dataset
dataSet.addSeries(new TimeSeries(nom_patient, Hour.class));
//dataSet.addSeries(series_ligne_2);
chart.setNotify(true);
chartPanel.setChart(chart);
chartPanel.removeAll();
chartPanel.repaint();
} catch (SQLException e) {
e.printStackTrace();
}
// 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);
this.setVisible(true);
}
} |
Partager