phpDocumentor VFront
Stats
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file stat.graph.php

Documentation is available at stat.graph.php

  1. <?php
  2. /**
  3. @desc Funzioni per la generazione dei grafici
  4. @package VFront
  5. @subpackage Stats
  6. @author Mario Marcello Verona <marcelloverona@gmail.com>
  7. @copyright 2007 Mario Marcello Verona
  8. @version 0.90
  9. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  10. */
  11.  
  12.  
  13. /**
  14.  * Funzione per la generazione dei grafici a barre
  15.  * Utilizza PEAR ed il pacchetto Image/Graph
  16.  * I grafici vengono generati nella cartella tmp in formato PNG
  17.  *
  18.  * @param array $data 
  19.  * @param array $labels 
  20.  * @param int $scala 
  21.  * @param string $testo 
  22.  * @param string $nome_file 
  23.  * @param int $x 
  24.  * @param int $y 
  25.  * @param mixed $colore 
  26.  * @param int $left 
  27.  * @param string $format 
  28.  * @param string $colore_sfondo 
  29.  * @return bool 
  30.  */
  31. function barre($data,$labels,$scala=5,$testo="",$nome_file="image",
  32.                 $x=490,$y=280,$colore='orange',$left=160,$format='%.2f'$colore_sfondo='ivory'){
  33.         
  34.     include_once 'Image/Graph.php';     
  35.     
  36.     $Graph =Image_Graph::factory('graph'array($x$y))
  37.  
  38.     // create the plotarea
  39.     $Graph->add(
  40.         Image_Graph::vertical(
  41.             Image_Graph::factory('title'array($testo12)),        
  42.             Image_Graph::vertical(
  43.                 $Plotarea Image_Graph::factory('plotarea'array('category''axis''horizontal')),
  44.                 $Legend Image_Graph::factory('legend'),
  45.                 90
  46.             ),
  47.             5
  48.         )
  49.     )
  50.     $Grid =$Plotarea->addNew('line_grid'array()IMAGE_GRAPH_AXIS_Y);
  51.     $Grid->setLineColor('black@0.1');   
  52.     
  53.     $Dataset =Image_Graph::factory('dataset')
  54.     
  55.     for($i=(count($data)-1);$i>=0;$i--){
  56.  
  57.         $Dataset->addPoint($labels[$i]$data[$i])
  58.     }
  59.  
  60.     $Font =$Graph->addNew('font''Verdana');
  61.     $Font->setSize(8);
  62.     
  63.     $Graph->setFont($Font)
  64.     
  65.     
  66.     $Graph->setBackgroundColor($colore_sfondo.'@0.2')
  67.     $Graph->setPadding(10)
  68.         
  69.     $Fill =Image_Graph::factory('Image_Graph_Fill_Array')
  70.     $Fill->addColor('white')
  71.     $Plotarea->setFillStyle($Fill);
  72.     
  73.     $Plot =$Plotarea->addNew('bar'&$Dataset)
  74.     
  75.     
  76.     if(is_array($colore)){
  77.         $Fill =Image_Graph::factory('gradient'array(IMAGE_GRAPH_GRAD_VERTICAL$colore[0]$colore[1]));
  78.         $Plot->setFillStyle($Fill)
  79.     }
  80.     else{
  81.         $Fill =Image_Graph::factory('Image_Graph_Fill_Array')
  82.         $Fill->addColor($colore)
  83.         $Plot->setFillStyle($Fill);
  84.     }
  85.  
  86.     
  87.     
  88.     
  89.     $Graph->donearray('filename' => FRONT_REALPATH."/tmp/$nome_file.png") )
  90.     
  91.     
  92.         
  93.         if(is_file(FRONT_REALPATH."/tmp/$nome_file.png"))
  94.             return true;
  95.         else 
  96.             return false;
  97.     }
  98.     
  99.     
  100.     
  101. /**
  102.  * Funzione per la generazione dei grafici a torta
  103.  * Utilizza PEAR ed il pacchetto Image/Graph
  104.  * Nella versione di Image/Graph 0.72 c'è un bug nella generazione delle etichette.
  105.  * Utilizzare la versione CVS o precedente|successiva del file Image/Graph/Plot/Pie.php
  106.  * I grafici vengono generati nella cartella tmp in formato PNG
  107.  *
  108.  * @param array $data 
  109.  * @param array $labels 
  110.  * @param string $testo 
  111.  * @param string $nome_file 
  112.  * @param int $x 
  113.  * @param int $y 
  114.  * @return bool 
  115.  */
  116. function torta($data,$labels,$testo="",$nome_file="image",$x=490,$y=300){
  117.  
  118.     
  119.     include_once 'Image/Graph.php';
  120.     // create the graph
  121.     $Graph =Image_Graph::factory('graph'array($x$y));
  122.     
  123.  
  124.     
  125.     
  126.         
  127.     // create the plotarea
  128.     $Graph->add(
  129.         Image_Graph::vertical(
  130.             Image_Graph::factory('title'array($testo12)),
  131.             Image_Graph::horizontal(
  132.                 $Plotarea Image_Graph::factory('plotarea'),
  133.                 $Legend Image_Graph::factory('legend'),
  134.                 70
  135.             ),
  136.             5          
  137.         )
  138.     );
  139.        $Legend->setPlotarea($Plotarea);
  140.         
  141.     $Dataset =Image_Graph::factory('dataset')
  142.     
  143.     for($i=(count($data)-1);$i>=0;$i--){
  144.  
  145.         $Dataset->addPoint($labels[$i]$data[$i],$labels[$i])
  146.     }
  147.     
  148.     $Plot =$Plotarea->addNew('pie'array(&$Dataset));
  149.     $Plotarea->hideAxis()
  150.     
  151.     
  152.     $Font =$Graph->addNew('font''Verdana');
  153.     $Font->setSize(6.5);
  154.     
  155.     $Graph->setFont($Font)
  156.     
  157.     
  158.     $Graph->setBackgroundColor('white')
  159.     $Graph->setPadding(10)
  160.     
  161.   
  162.     
  163.     
  164.     
  165.     
  166.     
  167.         
  168.     // create a Y data value marker
  169.     $Marker =$Plot->addNew('Image_Graph_Marker_Value'IMAGE_GRAPH_PCT_Y_TOTAL);
  170.     // create a pin-point marker type
  171.     $PointingMarker =$Plot->addNew('Image_Graph_Marker_Pointing_Angular'array(15&$Marker));
  172.     // and use the marker on the 1st plot
  173.     $Plot->setMarker($PointingMarker);    
  174.     // format value marker labels as percentage values
  175.     $Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted''%0.1f%%'));
  176.     
  177.     $Plot->Radius 2;
  178.     
  179.     $FillArray =Image_Graph::factory('Image_Graph_Fill_Array');
  180.     $Plot->setFillStyle($FillArray);
  181.     
  182.     for($i=0;$i<count($labels);$i++){
  183.     
  184.         $FillArray->addColor(generate_rand_hex_color(),$labels[$i]);
  185.         
  186.     }
  187.     
  188.     $Plot->explode(5);
  189.  
  190.     
  191.     // Mando l'output
  192.     $Graph->donearray('filename' => FRONT_REALPATH."/tmp/$nome_file.png") )
  193.  
  194.     if(is_file(FRONT_REALPATH."/tmp/$nome_file.png"))
  195.         return true;
  196.     else 
  197.         return false;
  198.         
  199. }
  200.  
  201.  
  202.  
  203. /**
  204.  * @desc Genera un seed per i numeri pseudocasuali
  205.  * @return float 
  206.  */
  207. function make_seed()
  208. {
  209.     list($usec$secexplode(' 'microtime());
  210.     return (float) $sec ((float) $usec 100000);
  211. }
  212.  
  213.  
  214.  
  215.  
  216. /**
  217.  * @desc Genera un colore pseudocasuale in formato esadecimale
  218.  * @return srting 
  219.  */
  220.     mt_srand(make_seed());
  221.     return "#".sprintf("%02X%02X%02X"mt_rand(0255)mt_rand(0255)mt_rand(0255));
  222. }
  223.  
  224. ?>

Documentation generated on Sat, 22 Sep 2007 11:51:23 +0200 by phpDocumentor 1.4.0a2