Problèmes jpgraph
patsak
-
pathos -
pathos -
Bonjour,
J'avance pas mal sur mon projet, mais j'ai quelques soucis. Je récupère par un formulaire quatre valeurs: date_ (date debut), date_f, capteur_d, capteur_f. Ensuite j'interroge ma base de données pour obtenir les valeurs correspondants à cette requête, et j'affiche le graph demandé. Voici mon code:
Code :
<?php
include ("C:\wamp\www\Stage_pageweb\jpgraph-2.3\src\jpgraph.php");
include ("C:\wamp\www\Stage_pageweb\jpgraph-2.3\src\jpgraph_line.php");
$connect= mysql_connect("localhost","root","") or die("Impossible de se connecter");
$db_selected=mysql_select_db('stage',$connect) or die('Impossible de sélectionner la BD');
$heure_d=' 00:00:00';
$heure_f=' 23:59:59';
$date_d=$_POST['date_d'].$heure_d;
$date_f=$_POST['date_f'].$heure_f;
$capteur_d=$_POST['capteur_d'];
$capteur_f=$_POST['capteur_f'];
///////////////////////////////////////////////////////////////////////////////////////
if ($_POST['display']=='highvoltage'){
$requete = "SELECT voltage,datetime
FROM testtable_data
WHERE '$date_d'<=datetime AND datetime<='$date_f'
AND '$capteur_d'<=id_captor AND id_captor<='$capteur_f'
";
$pg_result = mysql_query($requete);
$voltage=array();
$datetime=array();
$matrice = array();
$i=0;
while ($row = mysql_fetch_array($pg_result, MYSQL_ASSOC)) {
$datetime[$i]=($row["datetime"]);
$voltage[$i]=($row["voltage"]);
$matrice[$i] = array($datetime[$i],$voltage[$i]);
$i++;
}
$graph = new Graph(900,600,"auto");
$graph->SetShadow();
$graph->SetScale("textlin");
$graph->yaxis->SetColor("black","red");
$graph->title->Set("Highvoltage of captors $capteur_d to $capteur_f");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->img->SetMargin(30,140,30,140);
$graph->legend->Pos(0.03,0.5,"right","center");
$graph->xaxis->SetTextTickInterval(1);
$graph->xaxis->SetTextLabelInterval(1);
$graph->xaxis->SetTickLabels($datetime);
$graph->xaxis->SetLabelAngle(90);
$p1 = new LinePlot($voltage);
$p1->SetColor("red");
$p1->SetLegend("Voltage");
$graph->Add($p1);
$graph->Stroke();
mysql_close($connect);
}
?>
J'obtiens avec ceci plusieurs problèmes:
-pour le moment si je veux plusieurs capteurs, tout se mets sur la même courbe..et les date sont répliquées 2 fois
- si je sélectionne des dates trop éloignées (donc probablement trop de mesures) le graph ne s'affiche pas du tout...
Si quelqu'un peut me donner des idées parceque là je bloque, merci beaucoup
J'avance pas mal sur mon projet, mais j'ai quelques soucis. Je récupère par un formulaire quatre valeurs: date_ (date debut), date_f, capteur_d, capteur_f. Ensuite j'interroge ma base de données pour obtenir les valeurs correspondants à cette requête, et j'affiche le graph demandé. Voici mon code:
Code :
<?php
include ("C:\wamp\www\Stage_pageweb\jpgraph-2.3\src\jpgraph.php");
include ("C:\wamp\www\Stage_pageweb\jpgraph-2.3\src\jpgraph_line.php");
$connect= mysql_connect("localhost","root","") or die("Impossible de se connecter");
$db_selected=mysql_select_db('stage',$connect) or die('Impossible de sélectionner la BD');
$heure_d=' 00:00:00';
$heure_f=' 23:59:59';
$date_d=$_POST['date_d'].$heure_d;
$date_f=$_POST['date_f'].$heure_f;
$capteur_d=$_POST['capteur_d'];
$capteur_f=$_POST['capteur_f'];
///////////////////////////////////////////////////////////////////////////////////////
if ($_POST['display']=='highvoltage'){
$requete = "SELECT voltage,datetime
FROM testtable_data
WHERE '$date_d'<=datetime AND datetime<='$date_f'
AND '$capteur_d'<=id_captor AND id_captor<='$capteur_f'
";
$pg_result = mysql_query($requete);
$voltage=array();
$datetime=array();
$matrice = array();
$i=0;
while ($row = mysql_fetch_array($pg_result, MYSQL_ASSOC)) {
$datetime[$i]=($row["datetime"]);
$voltage[$i]=($row["voltage"]);
$matrice[$i] = array($datetime[$i],$voltage[$i]);
$i++;
}
$graph = new Graph(900,600,"auto");
$graph->SetShadow();
$graph->SetScale("textlin");
$graph->yaxis->SetColor("black","red");
$graph->title->Set("Highvoltage of captors $capteur_d to $capteur_f");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->img->SetMargin(30,140,30,140);
$graph->legend->Pos(0.03,0.5,"right","center");
$graph->xaxis->SetTextTickInterval(1);
$graph->xaxis->SetTextLabelInterval(1);
$graph->xaxis->SetTickLabels($datetime);
$graph->xaxis->SetLabelAngle(90);
$p1 = new LinePlot($voltage);
$p1->SetColor("red");
$p1->SetLegend("Voltage");
$graph->Add($p1);
$graph->Stroke();
mysql_close($connect);
}
?>
J'obtiens avec ceci plusieurs problèmes:
-pour le moment si je veux plusieurs capteurs, tout se mets sur la même courbe..et les date sont répliquées 2 fois
- si je sélectionne des dates trop éloignées (donc probablement trop de mesures) le graph ne s'affiche pas du tout...
Si quelqu'un peut me donner des idées parceque là je bloque, merci beaucoup