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
| <?php
include ("../jpgraph/src/jpgraph.php");
include ("../jpgraph/src/jpgraph_bar.php");
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', 'root');
define('MYSQL_PASS', 'a');
define('MYSQL_DATABASE', 'imprimantes_test');
$tableauDate = array();
$tableauCompteurs = array();
// ************************************************
// Extraction des données dans la base de données *
// ************************************************
$id_impr = ; //Doit prendre pour valeur l'identifiant de l'imprimante choisie dans la liste
$sql = <<<EOF
SELECT compteur AS COMPT,
date_releve AS JOUR
FROM compteurs
WHERE id_imprimante = '$id_impr'
ORDER BY date_releve DESC
LIMIT 0,30
EOF;
$mysqlCnx = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die('Problème de connexion mysql');
@mysql_select_db(MYSQL_DATABASE) or die('Problème de sélection de la base');
$mysqlQuery = @mysql_query($sql, $mysqlCnx) or die('Problème de requête');
while ($row = mysql_fetch_array($mysqlQuery, MYSQL_ASSOC))
{
$tableauDate[] = ' ' . $row['JOUR'];
$tableauCompteurs[] = $row['COMPT'];
$i++;
}
// Calcul de la différence entre les compteurs
$i = 1;
$j = array();
while ($i < (count($tableauCompteurs)-1))
{
$j[$i] = $tableauCompteurs[$i] - $tableauCompteurs[$i+1];
$i++;
}
// ***********************
// Création du graphique *
// ***********************
// Construction du conteneur
// Spécification largeur et hauteur
$graph = new Graph(2000,250);
// Réprésentation linéaire
$graph->SetScale("textlin");
// Ajouter une ombre au conteneur
$graph->SetShadow();
// Fixer les marges
$graph->img->SetMargin(40,30,25,40); // Gauche, droit, haut, bas
// Création du graphique histogramme
$bplot = new BarPlot($j);
// Spécification des couleurs des barres
$bplot->SetFillColor(array('red'));
//$bplot->SetFillGradient('#440000', '#FF9090', GRAD_LEFT_REFLECTION);
// Une ombre pour chaque barre
$bplot->SetShadow();
// Afficher les valeurs pour chaque barre
$bplot->value->Show();
// Fixer l'aspect de la police
$bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
// Modifier le rendu de chaque valeur
//$bplot->value->SetFormat('%d ventes');
// Ajouter les barres au conteneur
$graph->Add($bplot);
// Le titre
$graph->title->Set("Graphique 'HISTOGRAMME' : Compteurs");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Titre pour l'axe horizontal(axe x) et vertical (axe y)
$graph->xaxis->title->Set("Date");
$graph->yaxis->title->Set("Impressions par jour");
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Légende pour l'axe horizontal
$graph->xaxis->SetTickLabels($tableauDate);
// Afficher le graphique
$graph->Stroke();
?> |
Partager