Pxxo_Widget_ImageGraph

Ce petit widget permet de tracer des graphiques à partir d'une liste de points. Il est basé sur la package pear Image_Graph et permet si besoin de passer un instance d'un objet Image_Graph si on désire tracer des graph complexes.

Voila un exemple de ce qu'est capable de faire Image_Graph :

Plein d'exemples de graphiques complexes avec code php se trouvent sur ce site. Ce petit tutoriel peux également vous aider à construire votre graphique.

Ce widget n'est pas maintenu officiellement.

Paramètres

Nom Valeur par défaut Description
title 'mon graphique' Le titre du graphique
width 800 Largeur en pixel du graphique
height 600 Hauteur en pixel du graphique
points array( array('Janvier',10), …); Liste des points à tracer (liste de couples X,Y)
color 'red' La couleur du graphique
plottype 'bar' Le type de graphique. Les valeurs possibles sont : bar, line, smooth_area, area, ou step

Exemples

En utilisant les paramètres simplifiés du widget :

$params = array();
$params['title']    = 'Graphique personnalisé';
$params['width']    = 400;
$params['height']   = 300;
$params['points']   = array( array('10h', 47),
                             array('11h', 42),
                             array('12h', 32),
                             array('13h', 39),
                             array('14h', 25) );
$params['color']    = 'black';
$params['plottype'] = 'smooth_area'; // bar | line | smooth_area | area | step
$o = new Pxxo_Widget_ImageGraph($params);

En passant une instance de Image_Graph pour créer des graphiques complexes :

// exemple tiré de http://pear.veggerby.dk/samples/
require_once 'Image/Graph.php';
 
// create the graph
$Graph =& Image_Graph::factory('graph', array(400, 300)); 
$Graph->add(
    Image_Graph::vertical(
        Image_Graph::factory('title', array('Stacked Area Chart Sample', 12)),        
        Image_Graph::vertical(
            $Plotarea = Image_Graph::factory('plotarea'),
            $Legend = Image_Graph::factory('legend'),
            90
        ),
        5
    )
);
$Legend->setPlotarea($Plotarea);        
 
// create the dataset
$Datasets = 
    array(
        Image_Graph::factory('random', array(10, 2, 15, true)), 
        Image_Graph::factory('random', array(10, 2, 15, true)), 
        Image_Graph::factory('random', array(10, 2, 15, true))
    );
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('Image_Graph_Plot_Area', array($Datasets, 'stacked'));
 
// set a line color
$Plot->setLineColor('gray');
 
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$FillArray->addColor('blue@0.2');
$FillArray->addColor('yellow@0.2');
$FillArray->addColor('green@0.2');
 
// set a standard fill style
$Plot->setFillStyle($FillArray); 
 
$params = array();
$params['title']    = 'Graphique créé directement par PEAR/ImageGraph';
$params['pear_image_graph'] =& $Graph;
$o = new Pxxo_Widget_ImageGraph($params);
fr/doc/pxxo_widget_imagegraph.txt · Dernière modification: 2012/01/14 00:12 (édition externe)
 
 

©2003-2012 Pxxo

Partenaires : INIST-CNRS | Sourcesup | Web2.0 chat server | Jeux gratuits