Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks
Bibliothèques et frameworks Forum d'entraide sur les frameworks, templates, bibliothèques de code (PDFLib, eZPdf, JpGraph, Artichow, PEAR, etc). Avant de poster : FAQ bibliothèques, toutes les FAQ PHP et cours bibliothèques
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 16/02/2007, 15h03   #1
Membre confirmé
 
Inscription : janvier 2004
Messages : 537
Détails du profil
Informations forums :
Inscription : janvier 2004
Messages : 537
Points : 264
Points : 264
Par défaut [ImageGraph] Affichage de légende et position de graph

Bonjour,

J'utilise la bibliothèque Image_Graph et j'essaie de réaliser un graphique camembert comme celui-ci.

Voici mon code actuel :

Code :
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
<?php
/**
 * Usage example for Image_Graph.
 * 
 * Main purpose: 
 * Demonstrate radial gradient fillings
 * 
 * Other: 
 * None specific
 * 
 * $Id: misc03.php,v 1.4 2005/08/03 21:21:53 nosey Exp $
 * 
 * @package Image_Graph
 * @author Jesper Veggerby <pear.nosey@veggerby.dk>
 */
 
require_once 'Image/Graph.php';
 
// create the graph
$Graph =& Image_Graph::factory('graph', array(400, 300));
 
// add a TrueType font
$Font =& $Graph->addNew('font', 'Verdana');
// set the font size to 7 pixels
$Font->setSize(7);
 
$Graph->setFont($Font);
 
// create the plotarea
$Graph->add(
    Image_Graph::vertical(
        Image_Graph::factory('title', array('Structure par type de fonds', 12)),
        Image_Graph::horizontal(
            $Plotarea = Image_Graph::factory('plotarea'),
            $Legend = Image_Graph::factory('legend'),
            70
        ),
        5           
    )
);
 
$Legend->setPlotarea($Plotarea);
 
// create the 1st dataset
$Dataset1 =& Image_Graph::factory('dataset');
$Dataset1->addPoint('Item 1', 905);
$Dataset1->addPoint('Item 2', 95);
$Dataset1->addPoint('Item 3', 15);
/*$Dataset1->addPoint('Poultry', rand(1, 10));
$Dataset1->addPoint('Camels', rand(1, 10));
$Dataset1->addPoint('Other', rand(1, 10));*/
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('pie', array(&$Dataset1));
$Plotarea->hideAxis();
 
// create a Y data value marker
$Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL);
// create a pin-point marker type
$PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(-40, &$Marker));
// and use the marker on the 1st plot
$Plot->setMarker($PointingMarker);    
// format value marker labels as percentage values
$Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%'));
 
$Plot->Radius = 2;
 
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$Plot->setFillStyle($FillArray);
/*$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'green'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'blue'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'yellow'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'red'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'orange'));*/
$FillArray->addColor('blue@0.3', 'Color1');
$FillArray->addColor('orange@0.6', 'Color2');
$FillArray->addColor('green@0.6', 'Color3'); 
$FillArray->addColor('yellow@0.6', 'Color4'); 
$FillArray->addColor('black@0.6', 'Color5'); 
$FillArray->addColor('ref@0.6', 'Color6'); 
 
//$Plot->explode(5);
 
$PointingMarker->setLineColor(false);
$Marker->setBorderColor(false);
$Marker->setFillColor(false);
 
// output the Graph
$Graph->done();
?>
Mon problème est que la légende de droite n'apparaît pas (celle avec les couleurs et leurs significations).

Quelqu'un pourrait-il m'aider ?
Merci d'avance !
@+
__________________
N'oubliez pas le tag .
Merci de ne pas envoyer de MP pour des problèmes techniques.
navis84 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/02/2007, 10h21   #2
Membre confirmé
 
Inscription : janvier 2004
Messages : 537
Détails du profil
Informations forums :
Inscription : janvier 2004
Messages : 537
Points : 264
Points : 264
J'ai un peu avancé et voici le nouveau code actuel :

Code :
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
<?php
require_once 'Image/Graph.php';
 
 
				// paramètres du graphique
				$Canvas =& Image_Canvas::factory('png', array('width' => 400, 'height' => 300));      
				$Graph =& Image_Graph::factory('graph', $Canvas); 
 
				// définition du diagramme
				$Plotarea =& $Graph->addNew('plotarea'); 
 
				// définition des polices
				$Font =& $Graph->addNew('ttf_font', 'Verdana');
				$Font->setSize(7);
				$Graph->setFont($Font);
 
				// Titre du graphique
				$Legend =& $Plotarea->addNew('legend');
				//$Legend->setPlotarea($Plotarea);
				$Legend->setAlignment(IMAGE_GRAPH_ALIGN_TOP);
				//$titre = Image_Graph::factory('title', array("test", 11));
				//$Graph->add($titre);
 
// create the 1st dataset
$Dataset1 =& Image_Graph::factory('dataset');
$Dataset1->addPoint('Very Long Item 1', 905);
$Dataset1->addPoint('Item 2', 85);
$Dataset1->addPoint('Item 3', 15);
$Dataset1->addPoint('Item 4', 10);
/*$Dataset1->addPoint('Poultry', rand(1, 10));
$Dataset1->addPoint('Camels', rand(1, 10));
$Dataset1->addPoint('Other', rand(1, 10));*/
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('pie', array(&$Dataset1));
$Plotarea->hideAxis();
 
// create a Y data value marker
$Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL);
// create a pin-point marker type
$PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(-40, &$Marker));
// and use the marker on the 1st plot
$Plot->setMarker($PointingMarker);    
// format value marker labels as percentage values
$Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%'));
 
$Plot->Radius = 2;
 
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$Plot->setFillStyle($FillArray);
/*$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'green'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'blue'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'yellow'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'red'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', 'orange'));*/
$FillArray->addColor('blue@0.3', 'Color1');
$FillArray->addColor('orange@0.6', 'Color2');
$FillArray->addColor('green@0.6', 'Color3'); 
$FillArray->addColor('yellow@0.6', 'Color4'); 
//$FillArray->addColor('black@0.6', 'Color5'); 
//$FillArray->addColor('ref@0.6', 'Color6'); 
 
//$Plot->explode(5);
 
$PointingMarker->setLineColor(false);
$Marker->setBorderColor(false);
$Marker->setFillColor(false);
 
// output the Graph
$Graph->done();
?>
Or, j'aimerais que le graphique soit aligné à gauche et que la légende ne possède pas de cadre... Comment faire ?
__________________
N'oubliez pas le tag .
Merci de ne pas envoyer de MP pour des problèmes techniques.
navis84 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/02/2007, 12h33   #3
Membre confirmé
 
Inscription : janvier 2004
Messages : 537
Détails du profil
Informations forums :
Inscription : janvier 2004
Messages : 537
Points : 264
Points : 264
J'ai trouvé comment enlever la bordure de la légende :

Code :
$Legend->setLineColor('');

Il ne me reste plus qu'à positionner le graphique (camembert) en bas à gauche de l'image...
Auriez-vous une idée svp ?
__________________
N'oubliez pas le tag .
Merci de ne pas envoyer de MP pour des problèmes techniques.
navis84 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h12.


 
 
 
 
Partenaires

Hébergement Web