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
| <?php
require_once('Artichow/BarPlot.class.php');
//Connexion au serveur MySQL
$db=mysql_connect("localhost","v_util","vpc@2006") or die ("erreur de connexion".mysql_error());
//ouverture de la base bac
mysql_select_db("bac",$db)or die("erreur de connexion à la base ");
//tableau de resultat
$annee = array();
$pourcentage = array();
$sql = "SELECT annee, pourcentage FROM resultat" or die('req invalide');
$req = mysql_query($sql);
while($result = mysql_fetch_array($req)){
array_push($pourcentage, $result[0]);
array_push($annee, $result[1]);
}
//creation du graphique : batons
$graph = new Graph(500,500);
$graph->setAntiAliasing(TRUE);
//Creation du LinePlot
$plot = new BarPlot($annee);
//ajoute une couleur de fond aux barres
$plot->setBarColor(
new Color(255, 250, 250)
);
//On un ajoute un titre
$plot->title->set("Résultats du BAC STG GSI");
$plot->title->setFont(new TuffyBold(11));
$plot->title->border->show();
$plot->title->setBackgroundColor(new Color(255, 255, 255, 25));
$plot->title->setPadding(4, 4, 4, 4);
$plot->title->move(-20, 25);
// Ajout du titre de l'axe des Y
$plot->yAxis->title->set("Pourcentage");
$plot->yAxis->title->setFont(new TuffyBold(10));
$plot->yAxis->title->move(-4, 0);
$plot->yAxis->setTitleAlignment(Label::TOP);
//Ajout du titre de l'axe des X
$plot->xAxis->title->set("Année");
$plot->xAxis->title->setFont(new TuffyBold(10));
$plot->xAxis->setTitleAlignment(Label::RIGHT);
// On ajoute 5 % d'espace à gauche et à droite de l'histogramme.
// On ne change pas l'espace du haut et du bas de l'histogramme.
$plot->setSpace(
5, /* Gauche */
5, /* Droite */
NULL, /* Haut */
NULL /* Bas */
);
// On choisit une ombre de 3 pixels
$plot->barShadow->setSize(3);
// On place l'ombre sur les côtés haut et droit.
// Si vous utilisez Artichow pour PHP 4 & 5, transformez Shadow::RIGHT_TOP en SHADOW_RIGHT_TOP
$plot->barShadow->setPosition(Shadow::RIGHT_TOP);
// On veut une ombre de couleur grise
$plot->barShadow->setColor(new Color(256, 180, 180, 10));
// On choisit de lisser les extrémités de l'ombre
$plot->barShadow->smooth(TRUE);
//Affichage des noms sur l'axe X
$plot->xAxis->setLabelText($pourcentage);
//Affichage du graphe
$graph->add($plot);
$graph->draw();
// fermer la connexion à la base
mysql_close($db);
?> |
Partager