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
|
<?php
include 'database.php';
require_once ("jpgraph/jpgraph.php");
require_once ("jpgraph/jpgraph_line.php");
// recupération des données dans la base
$base=DBconnect('localhost', 'root', '', 'mybase');
$sql = 'SELECT date, valeur FROM data_temp ORDER BY date';
$res = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$vx[] = array();
$vy[] = array();
while ($data = mysql_fetch_array($res)) {
$vx[] = $data['date'];
$vy[] = $data['valeur'];
}
mysql_free_result($res);
DBdisconnect($base);
// construction du graphique
$graph = new Graph(300,250);
$graph->img->SetMargin(40,40,40,80);
$graph->img->SetAntiAliasing();
$graph->SetScale("linlin");
$graph->SetShadow();
$graph->title->Set("Example slanted X-labels");
$graph->title->SetFont(FF_VERDANA,FS_NORMAL,14);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,11);
$graph->xaxis->SetTickLabels($vx);
$graph->xaxis->SetLabelAngle(45);
$p1 = new LinePlot($vy);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("blue");
$p1->SetCenter();
$graph->Add($p1);
$graph->Stroke();
?> |
Partager