Image_Graph
[ class tree: Image_Graph ] [ index: Image_Graph ] [ all elements ]

Source for file linechart1.php

Documentation is available at linechart1.php

  1. <?php
  2.     include('Image/Graph.php');
  3.     
  4.     function XtoYear($Value{
  5.         return floor($Value+1998);
  6.     }
  7.     
  8.     function salaries($Value{
  9.         // I wish!
  10.         return exp($Value)+1000;
  11.     }
  12.     
  13.     // create the graph as a 500 x 300 image
  14.     $Graph =Image_Graph::factory('graph'array(600300));      
  15.     
  16.     // create a random dataset to use for demonstrational purposes
  17.     $DataSet =Image_Graph::factory('Image_Graph_Dataset_Function'array(19'salaries'9));
  18.     
  19.     $DataSet2 =Image_Graph::factory('dataset');
  20.     $DataSet2->addPoint('CEO'10);
  21.     $DataSet2->addPoint('TAP'32)
  22.     $DataSet2->addPoint('TBF'13)
  23.     $DataSet2->addPoint('ABC'19)
  24.     $DataSet2->addPoint('QED'26)
  25.     
  26.     // create the title font
  27.     $Font =$Graph->addNew('ttf_font''arial.ttf');
  28.     $Font->setSize(11);       
  29.     
  30.     // create the title font
  31.     $VerticalFont =$Graph->addNew('Image_Graph_Font_Vertical');
  32.     $Font->setSize(11);
  33.     
  34.     // add a plot area in a vertical layout to display a title on top 
  35.     $Graph->add(
  36.         Image_Graph::vertical(
  37.             Image_Graph::factory('title'array('Annual income'&$Font)),
  38.             Image_Graph::horizontal(          
  39.                 $Plotarea = Image_Graph::factory('plotarea'),
  40.                 $Plotarea2 = Image_Graph::factory('plotarea')
  41.             ),                
  42.             5
  43.         ),
  44.         5
  45.     );
  46.     
  47.     //
  48.     $Grid =$Plotarea->addNew('bar_grid'nullIMAGE_GRAPH_AXIS_Y);
  49.     $Grid->setFillStyle(Image_Graph::factory('gradient'array(IMAGE_GRAPH_GRAD_VERTICAL'white''lightgrey')));       
  50.     
  51.     // add the line plot to the plotarea
  52.     $Plot =$Plotarea->addNew('line'&$DataSet);
  53.     
  54.     // add coins-icon as marker
  55.     $Plot->setMarker(Image_Graph::factory('Image_Graph_Marker_Icon''./images/coins.png'));
  56.     
  57.     $AxisX =$Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
  58.     $AxisY =$Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
  59.     // make x-axis start at 0
  60.     $AxisX->forceMinimum(0);
  61.     
  62.     // make x-axis end at 11
  63.     $AxisX->forceMaximum(9);
  64.     
  65.     // show axis arrows
  66.     $AxisX->showArrow();  
  67.     $AxisY->showArrow();
  68.     
  69.     // create a datapreprocessor to map X-values to years
  70.     $AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function''XtoYear'));
  71.     $AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Currency'"US$"));    
  72.     
  73.     $Plot2 =$Plotarea2->addNew('Image_Graph_Plot_Pie'&$DataSet2);
  74.     $Plotarea2->hideAxis();
  75.     $Fill =Image_Graph::factory('Image_Graph_Fill_Array');
  76.     $Fill->addNew('gradient'array(IMAGE_GRAPH_GRAD_RADIAL'red''white'));
  77.     $Fill->addNew('gradient'array(IMAGE_GRAPH_GRAD_RADIAL'blue''white'));
  78.     $Fill->addNew('gradient'array(IMAGE_GRAPH_GRAD_RADIAL'yellow''white'));
  79.     $Fill->addNew('gradient'array(IMAGE_GRAPH_GRAD_RADIAL'green''white'));
  80.     $Fill->addNew('gradient'array(IMAGE_GRAPH_GRAD_RADIAL'orange''white'));
  81.     $Plot2->setFillStyle($Fill);
  82.     
  83.     $Marker2 =$Graph->addNew('Image_Graph_Marker_Value'IMAGE_GRAPH_VALUE_Y);
  84.     $Plot2->setMarker($Marker2);
  85.     $Marker2->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted''%0.0f%%'));    
  86.     
  87.     // output the graph
  88.     $Graph->done();
  89. ?>

Documentation generated on Mon, 11 Mar 2019 13:57:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.