Bonjour,
J'ai effectué un graphique via une BDD.
Sur ma page index, je sélectionne le type de graph à afficher et celui-ci s'affiche correctement.
J'ai fait en sorte que mes données soient sélectionnées en fonction d'une période.
Mon fichier requêtes :
Index :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if (!empty($_POST['date1'])) { $pDate1 = $_POST['date1']; } else { $pDate1 = ' '; } if (!empty($_POST['date2'])) { $pDate2 = $_POST['date2']; } else { $pDate2 = ' '; } // Création des Requètes if (empty($_POST['date1']) || empty($_POST['date2'])) { $REQ_Total_Arrets_Station = $bdd->prepare('SELECT COUNT(Arret.IDArret) AS nbArrets, Station.nomStation AS nomStation, Ligne.NomLigne AS NomLigne, Station.IDStation AS IDStation, ligne.IDLigne AS IDLigne FROM Ligne, Arret, Station WHERE Station.IDStation = Arret.IDStation AND Ligne.IDLigne = Arret.IDLigne GROUP BY Arret.IDStation, Arret.IDLigne ORDER BY nbArrets DESC'); $REQ_Total_Arrets_Ligne = $bdd->prepare('SELECT COUNT(Arret.IDArret) AS nbArrets, Ligne.NomLigne AS NomLigne, Arret.IDLigne AS IDLigne FROM Ligne, Arret WHERE Arret.IDLigne = Ligne.IDLigne GROUP BY Arret.IDLigne ORDER BY nbArrets DESC'); $REQ_Total_Arrets_Station->execute(); $REQ_Total_Arrets_Ligne->execute(); } else { $REQ_Total_Arrets_Station = $bdd->prepare('SELECT COUNT(Arret.IDArret) AS nbArrets, Station.nomStation AS nomStation, Ligne.NomLigne AS NomLigne, Station.IDStation AS IDStation, ligne.IDLigne AS IDLigne FROM Ligne, Arret, Station WHERE Station.IDStation = Arret.IDStation AND Ligne.IDLigne = Arret.IDLigne AND arret.Date_arret >= ? AND arret.Date_arret <= ? GROUP BY Arret.IDStation, Arret.IDLigne ORDER BY nbArrets DESC'); $REQ_Total_Arrets_Station->execute(array($pDate1,$pDate2)); $REQ_Total_Arrets_Ligne = $bdd->prepare('SELECT COUNT(Arret.IDArret) AS nbArrets, Ligne.NomLigne AS NomLigne, Arret.IDLigne AS IDLigne FROM Ligne, Arret WHERE Arret.IDLigne = Ligne.IDLigne AND arret.Date_arret >= ? AND arret.Date_arret <= ? GROUP BY Arret.IDLigne ORDER BY nbArrets DESC'); $REQ_Total_Arrets_Ligne->execute(array($pDate1,$pDate2)); }
Puis mon graph :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php include ("requetes.php"); ?> <header> <?php include ("header.php"); if(!empty($_POST['mode'])) { $mode = $_POST['mode']; switch ($mode) { case 1: echo '<img src="graph_Arrets_Station.php">'; break; case 2: ?> <img src="graph_dechets_Type.php"> <?php break; case 3: while($data = $REQ_Total_Arrets_Station->fetch()) { echo '<pre>'; print_r($data); echo '</pre>'; } } } ?>
J'utilise un simple formulaire avec deux dates , une sélection du type de graph à afficher et un bouton actualiser qui pointe sur mon index.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php include ("requetes.php"); include ("jpgraph/src/jpgraph.php"); include ("jpgraph/src/jpgraph_bar.php"); $tab_ligne = array(); $tab_Dechet = array(); $nomType_Dechet = array(); $presenceLigne = 0; $nbTypeDechet = 0; $nbLignes = 0; $i = 0; $j=0; $sommeGraphDechet = array(); $pos = 0; while($data = $REQ_nbTypeDechet->fetch()) { $nbTypeDechet += $data['nbTypeDechet']; }$REQ_nbTypeDechet->closeCursor(); while($data = $REQ_nbLignes->fetch()) { $nbLignes+= $data['nbLignes']; }$REQ_nbLignes->closeCursor(); //Création d'un tableau fixe par Type dechet for ($i=0; $i < $nbTypeDechet; $i++) { $tab_Dechet[$i] = array(); for ($j=0; $j < $nbLignes; $j++) { $tab_Dechet[$i][] = 0; } } while ($data = $REQ_Total_Dechets_Ligne->fetch()) { $tab_ligne[] = $data['nomLigne']; }$REQ_Total_Dechets_Ligne->closeCursor(); //récupération des Lignes en supprimant les réccurences while ($data = $REQ_Total_Dechets_Type->fetch()) { //Récupération de la position de la ligne dans le tableau $pos = array_search($data['NomLigne'],$tab_ligne); //récupération des valeurs et stockage dans le tableau correspondant for ($i=0; $i < $nbTypeDechet; $i++) { if($i == $data['IDType_dechet']-1 ) { $tab_Dechet[$i][$pos] = $data['nbDechets']; $nomType_Dechet[$i] = $data['nomType_Dechet']; } } $presenceLigne = 0; }$REQ_Total_Dechets_Type->closeCursor(); // Création d'un histogramme par Type dechet for ($i=0 ; $i < $nbTypeDechet ; $i++) { ${'dechet'.$i} = new BarPlot($tab_Dechet[$i]); ${'dechet'.$i}->SetLegend($nomType_Dechet[$i]); } // Stockage des objets dans un tableau for ($i=0; $i < $nbTypeDechet; $i++) { $sommeGraphDechet[] = ${'dechet'.$i}; } // ********************** // Création du graphique // ********************** $graph = new Graph(1200,800,"auto"); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(60,40,50,40); $graph->SetMarginColor('#CCCCFF'); $graph->title->Set("Nombre de dechets par Type sur lignes MGG"); $graph->title->SetMargin(20); $graph->title->SetFont(FF_COMIC,FS_BOLD,12); // Créer l'ensemble d'histogrammes accumulés $gbplot = new AccBarPlot($sommeGraphDechet); // Position de la légende $graph->legend->Pos(0.12,0.12,"right","top"); // Ajouter l'ensemble accumulé $graph->Add($gbplot); // Afficher les valeurs de chaque histogramme groupé $gbplot->value->Show(); $gbplot->value->SetFont(FF_COMIC,FS_NORMAL,8); $gbplot->value->SetFormat('%d'); for ($i=0; $i < $nbTypeDechet; $i++) { ${'dechet'.$i}->value->Show(); ${'dechet'.$i}->value->SetFont(FF_COMIC,FS_NORMAL,8); ${'dechet'.$i}->value->SetColor('black'); ${'dechet'.$i}->value->SetFormat('%d'); ${'dechet'.$i}->setValuePos('center'); } // Paramétrer les axes X et Y $graph->yaxis->title->Set("Nombre de dechets"); $graph->yaxis->title->SetMargin(20); $graph->yaxis->title->SetFont(FF_COMIC,FS_BOLD); $graph->xaxis->title->Set("Ligne"); $graph->xaxis->SetTickLabels($tab_ligne); $graph->xaxis->title->SetMargin(4); $graph->xaxis->title->SetFont(FF_COMIC,FS_BOLD); // Afficher l'image générée $graph->Stroke(); ?>
L'idée est que si on ne saisi pas de dates, le graphique affiche tout ce qu'il peut via une REQ sans dates.
Si l'on saisi des dates, les REQ avec dates sont exécutées.
Seulement voila , lorsque j'ouvre mon index aucune date n'est sélectionnée ce qui est logique. Mon graph se forme donc avec toutes les valeurs.
Mais si je choisi des dates, le graphique reste le même étant donnée que le code n'est pas rechargé.
Seulement le graph ne s'affiche pas si je fais un include.
Avez-vous une idée afin de re-charger le graph avec les nouvelles données de REQ et réussir à l'afficher sur mon index ?
Salutations,
Partager