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
| <?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
// define les constants de connexion
define('MYSQL_HOST','localhost');
define('MYSQL_USER','root');
define('MYSQL_PASS','');
define('MYSQL_DATABASE','tuto_jp_graph');
// include des librairie JP graph
include_once ('../../jpgraph/src/jpgraph.php');
include_once ('../../jpgraph/src/jpgraph_line.php');
// Initialisation des données
$tab_Annee=array();
$tab_Nb_Ventes=array();
$moisfr=array('Jan','Fev','Mar','Avr','Mai','Jui','Juil','Aout','Sept','Oct','Nov','Dec');
// connexion à la BDD
$connexion=@mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS)
OR DIE ('PB de la connexion de la BDD'.mysql.error());
$db_name=@mysql_select_db(MYSQL_DATABASE)
OR DIE('PB de la BDD '.mysql_error());
// preparer les requetes concerné
$sql="SELECT MONTH(DTHR_VENTE) AS Mois,
COUNT(ID) AS Nombre_produit,
SUM(PRIX) AS vendu
FROM ventes
WHERE YEAR(DTHR_VENTE)=2006
GROUP BY Mois";
$result=@mysql_query($sql,$connexion)
OR DIE ('PB de la requete'.mysql.error());
// initialiser le valeur de chaque mois en 0;
$tabventes2006=array(0,0,0,0,0,0,0,0,0,0,0,0);
while($row=@mysql_fetch_array($result,MYSQL_ASSOC)) {
$tabventes2006[$row['Mois']-1]=$row['vendu'];
}
// Creation du conteneur du courbe: graph
$graph=new Graph(500,300);
// Definir le titre de graph
$graph->title->set("Graphique 'courbes': Volumes des ventes 2006");
// definirle margin
$graph->img->SetMargin(50,30,30,50);
// Mettre un background image
$graph->SetBackgroundGradient('white','silver');
//lissage sur fond blanc : eviter la pixellisation
//$graph->img->SetAntiLiasing('white');
//les types des axes x,y
$graph->SetScale("textlin");
//Ajouter un shadow
$graph->SetShadow('red',5);
/*$theme= new AquaTheme();
$graph->SetTheme($theme);
$graph->SetFrame(true,'red');*/
// Afficher la grille de l'axe y
$graph->ygrid->SetColor('blue');
$graph->ygrid->SetLineStyle('dashed');
$graph->ygrid->SetFill(true,'#EFEFEF@0.9','#BBCCFF@0.9');
$graph->ygrid->Show();
// Afficher la grille de l'axe y
$graph->xgrid->SetColor('red');
$graph->xgrid->SetLineStyle('dashed');
$graph->xgrid->SetFill(true,'#EFEFEF@0.9','#BBCCFF@0.9');
$graph->xgrid->Show();
//la police de graph conteneur
$graph->title->SetFont(FF_ARIAL,FS_BOLD,11);
// creation du courbe et representation des données
$courbe= new LinePlot($tabventes2006);
// police et valeur de format : value for the courbe
$courbe->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$courbe->value->SetFormat('%d');
$courbe->value->SetColor('red');
$courbe->value->show();
// description of point of each value of graph courbe
// type de point
$courbe->mark->SetType(MARK_FILLEDCIRCLE);
$courbe->mark->SetFillColor("red");
$courbe->mark->SetWidth(5);
// couleur de la courbe
$courbe->SetColor("blue");
$courbe->SetCenter();
//Parametrages de l'axes
$graph->xaxis->title->Set("Mois");
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetTickLabels($moisfr);
// axe Y
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
// ajouter l'image au graph
$graph->Add($courbe);
$graph->Stroke(); |
Partager