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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Mon super site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="design.css" rel="stylesheet" type="text/css" media="screen, handheld, tv, projection" />
</head>
<body>
<?php
$tableauPersonne = array();
$tableauNombreCD = array();
$tableauAge = array();
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=maBase', 'root', '', $pdo_options);
$reponse = $bdd->query('SELECT * FROM personne');
// On affiche chaque entrée une à une
while ($donnees = $reponse->fetch())
{
$tableauPersonne[] = $donnees['nom'];
$tableauAge[] = $donnees['age'];
$tableauNombreCD[] = $donnees['nombre_cd'];
}
$reponse->closeCursor(); // Termine le traitement de la requête
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
<table id="table">
<caption class = "caption">Valeurs à mettre dans le graphique</caption>
<tr id="id">
<td>Nom</td>
<td>Age</td>
<td>nombre de CD</td>
</tr>
<tr class = "personne">
<td><?php print_r($tableauPersonne[0]); ?></td>
<td><?php print_r($tableauAge[0]); ?></td>
<td><?php print_r($tableauNombreCD[0]); ?></td>
</tr>
<tr class = "personne">
<td><?php print_r($tableauPersonne[1]); ?></td>
<td><?php print_r($tableauAge[1]); ?></td>
<td><?php print_r($tableauNombreCD[1]); ?></td>
</tr>
<tr class = "personne">
<td><?php print_r($tableauPersonne[2]); ?></td>
<td><?php print_r($tableauAge[2]); ?></td>
<td><?php print_r($tableauNombreCD[2]); ?></td>
</tr>
<tr class = "personne">
<td><?php print_r($tableauPersonne[3]); ?></td>
<td><?php print_r($tableauAge[3]); ?></td>
<td><?php print_r($tableauNombreCD[3]); ?></td>
</tr>
</table>
<?php
@include ("./jpgraph/src/jpgraph.php");
@include ("./jpgraph/src/jpgraph_bar.php");
// Construction du conteneur
// Spécification largeur et hauteur
$graph = new Graph(400,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);
// Création du graphique histogramme
$bplot = new BarPlot($tableauNombreCD);
// Spécification des couleurs des barres
$bplot->SetFillColor(array('red', 'green', 'blue', 'orange'));
// 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 personne');
// Ajouter les barres au conteneur
$graph->Add($bplot);
// Le titre
$graph->title->Set("Graphique 'HISTOGRAMME' : nombre de CD par personnes");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Titre pour l'axe horizontal(axe x) et vertical (axe y)
$graph->xaxis->title->Set("Personnes");
$graph->yaxis->title->Set("Nombre de CD");
$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($tableauPersonne);
// Afficher le graphique
$graph->Stroke();
?>
</body>
</html> |
Partager