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

Documentation generated on Mon, 11 Mar 2019 14:21:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.