| 66 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package annuaire
|
|
|
7 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
8 |
* @copyright 2010 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version SVN: <svn_id>
|
|
|
11 |
* @link /doc/annuaire/
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class Statistiques {
|
|
|
15 |
|
|
|
16 |
const GRAPH_CAMEMBERT = 'pie';
|
|
|
17 |
const GRAPH_COURBE = 'courbe';
|
|
|
18 |
|
| 232 |
aurelien |
19 |
public function genererGraphique($type_graphique, $valeurs, $titre = '', $taille = array(800, 800), $nom_axe_x = '', $nom_axe_y = '') {
|
| 66 |
aurelien |
20 |
|
|
|
21 |
// Inclusion de la librairie JpGraph
|
|
|
22 |
include_once("lib/jpgraph.php");
|
|
|
23 |
$graph = null;
|
|
|
24 |
|
|
|
25 |
switch($type_graphique) {
|
|
|
26 |
case Statistiques::GRAPH_CAMEMBERT:
|
| 232 |
aurelien |
27 |
$graph = $this->genererGraphiqueCamembert($valeurs, $titre, $taille);
|
| 66 |
aurelien |
28 |
break;
|
|
|
29 |
|
|
|
30 |
case Statistiques::GRAPH_COURBE:
|
| 232 |
aurelien |
31 |
$graph = $this->genererGraphiqueCourbe($valeurs, $titre, $taille, $nom_axe_x, $nom_axe_y);
|
| 66 |
aurelien |
32 |
break;
|
|
|
33 |
|
|
|
34 |
default:
|
|
|
35 |
$graph = $this->genererGraphiqueCourbe($valeurs);
|
|
|
36 |
break;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
return $graph;
|
|
|
40 |
}
|
|
|
41 |
|
| 232 |
aurelien |
42 |
public function genererGraphiqueCamembert($valeurs, $titre, $taille) {
|
| 66 |
aurelien |
43 |
|
|
|
44 |
include_once("lib/jpgraph_pie.php");
|
| 232 |
aurelien |
45 |
$graph = new PieGraph($taille[0],$taille[1]);
|
| 223 |
aurelien |
46 |
|
|
|
47 |
$legendes = array_keys($valeurs);
|
|
|
48 |
|
|
|
49 |
$valeurs = array_values($valeurs);
|
| 66 |
aurelien |
50 |
|
| 223 |
aurelien |
51 |
$oPie = new PiePlot($valeurs);
|
|
|
52 |
$oPie->SetLegends($legendes);
|
| 66 |
aurelien |
53 |
|
|
|
54 |
// Ajouter le titre du graphique
|
|
|
55 |
$graph->title->Set($titre);
|
|
|
56 |
|
|
|
57 |
// position du graphique (légèrement à droite)
|
| 232 |
aurelien |
58 |
$oPie->SetCenter(0.35);
|
| 66 |
aurelien |
59 |
|
|
|
60 |
$oPie->SetValueType(PIE_VALUE_PER);
|
|
|
61 |
|
|
|
62 |
// Format des valeurs de type "entier"
|
| 223 |
aurelien |
63 |
$oPie->value->SetFormat('%1.2f%%');
|
| 66 |
aurelien |
64 |
|
|
|
65 |
$graph->Add($oPie);
|
| 232 |
aurelien |
66 |
return $graph;
|
| 66 |
aurelien |
67 |
}
|
|
|
68 |
|
| 232 |
aurelien |
69 |
public function genererGraphiqueCourbe($valeurs, $titre, $taille, $nom_axe_x, $nom_axe_y) {
|
| 66 |
aurelien |
70 |
|
|
|
71 |
include_once("lib/jpgraph_line.php");
|
|
|
72 |
|
|
|
73 |
// Création du conteneur
|
| 232 |
aurelien |
74 |
$graph = new Graph($taille[0],$taille[1],"auto");
|
| 66 |
aurelien |
75 |
|
| 232 |
aurelien |
76 |
$graph->img->SetMargin(50,30,50,100);
|
| 66 |
aurelien |
77 |
|
|
|
78 |
// Lissage sur fond blanc (évite la pixellisation)
|
|
|
79 |
$graph->img->SetAntiAliasing("white");
|
| 232 |
aurelien |
80 |
$graph->SetMarginColor("white");
|
| 66 |
aurelien |
81 |
|
|
|
82 |
// A détailler
|
|
|
83 |
$graph->SetScale("textlin");
|
|
|
84 |
|
|
|
85 |
// Ajouter une ombre
|
|
|
86 |
$graph->SetShadow();
|
|
|
87 |
|
|
|
88 |
// Ajouter le titre du graphique
|
|
|
89 |
$graph->title->Set($titre);
|
|
|
90 |
|
|
|
91 |
// Afficher la grille de l'axe des ordonnées
|
|
|
92 |
$graph->ygrid->Show();
|
|
|
93 |
// Fixer la couleur de l'axe (bleu avec transparence : @0.7)
|
| 232 |
aurelien |
94 |
$graph->ygrid->SetColor('#E6E6E6@0.7');
|
| 66 |
aurelien |
95 |
// Des tirets pour les lignes
|
|
|
96 |
$graph->ygrid->SetLineStyle('solid');
|
|
|
97 |
|
|
|
98 |
// Afficher la grille de l'axe des abscisses
|
| 232 |
aurelien |
99 |
//$graph->xgrid->Show();
|
| 66 |
aurelien |
100 |
// Fixer la couleur de l'axe (rouge avec transparence : @0.7)
|
| 232 |
aurelien |
101 |
//$graph->xgrid->SetColor('red@0.7');
|
| 66 |
aurelien |
102 |
// Des tirets pour les lignes
|
| 232 |
aurelien |
103 |
//$graph->xgrid->SetLineStyle('solid');
|
|
|
104 |
$graph->xaxis->SetLabelAngle(90);
|
|
|
105 |
$graph->xaxis->SetTextLabelInterval(4);
|
| 66 |
aurelien |
106 |
|
|
|
107 |
// Créer une courbes
|
|
|
108 |
$courbe = new LinePlot(array_values($valeurs));
|
|
|
109 |
|
|
|
110 |
// Chaque point de la courbe ****
|
|
|
111 |
// Type de point
|
|
|
112 |
$courbe->mark->SetType(MARK_FILLEDCIRCLE);
|
|
|
113 |
// Couleur de remplissage
|
| 232 |
aurelien |
114 |
$courbe->mark->SetFillColor("red");
|
| 66 |
aurelien |
115 |
// Taille
|
| 232 |
aurelien |
116 |
$courbe->mark->SetWidth(1);
|
| 66 |
aurelien |
117 |
|
|
|
118 |
// Paramétrage des axes
|
| 232 |
aurelien |
119 |
//$graph->xaxis->title->Set($nom_axe_x);
|
|
|
120 |
$txt = new Text($nom_axe_x,270,460);
|
| 66 |
aurelien |
121 |
$graph->xaxis->SetTickLabels(array_keys($valeurs));
|
|
|
122 |
|
|
|
123 |
// Paramétrage des axes
|
|
|
124 |
$graph->yaxis->title->Set($nom_axe_y);
|
|
|
125 |
|
|
|
126 |
// Ajouter la courbe au conteneur
|
|
|
127 |
$graph->Add($courbe);
|
|
|
128 |
|
| 232 |
aurelien |
129 |
return $graph;
|
| 66 |
aurelien |
130 |
}
|
|
|
131 |
|
| 232 |
aurelien |
132 |
public function combinerGraphiques($graph1, $graph2, $taille) {
|
| 66 |
aurelien |
133 |
|
|
|
134 |
include_once('lib/jpgraph_mgraph.php');
|
| 232 |
aurelien |
135 |
$mgraph = new MGraph($taille[0],$taille[1],"auto");
|
|
|
136 |
$xpos1=300;$ypos1=3;
|
|
|
137 |
$xpos2=3;$ypos2=200;
|
|
|
138 |
|
|
|
139 |
$graph1->SetFrame(false);
|
|
|
140 |
$graph2->SetFrame(false);
|
|
|
141 |
|
|
|
142 |
//$xpos3=3;$ypos3=1000;
|
|
|
143 |
$mgraph->Add($graph1,$xpos1,$ypos1);
|
|
|
144 |
$mgraph->Add($graph2,$xpos2,$ypos2);
|
|
|
145 |
$mgraph->SetShadow();
|
|
|
146 |
//$mgraph->Add($graph['experience_bota'],$xpos3,$ypos3);
|
|
|
147 |
return $mgraph;
|
| 66 |
aurelien |
148 |
}
|
| 232 |
aurelien |
149 |
|
|
|
150 |
public function dessinerGraph($graph) {
|
|
|
151 |
return $graph->Stroke(_IMG_HANDLER);
|
|
|
152 |
}
|
| 66 |
aurelien |
153 |
|
|
|
154 |
}
|
|
|
155 |
?>
|