SourceForge.net  |  Sunyday.net
Last release: 1.27d
a PHP Class to build Charts
pChart 2.x is born, you can start moving your script to this new version. The new website is at www.pchart.net.
Overview  |  Screenshots  |  Download  |  Add-ons  |  Demonstration  |  Support  |  :: Documentation ::
Documentation Contents
Overview
Class definition
FAQ
Digging with pChart
Basic Examples
Advanced Examples
Graphs labels
Small "Fast Graphs"
Using pCache
Line style, Pics inclusion
Importing CSV data
Error reporting
Missing values
Playing with axis formats
Playing with backgrounds
High quality graphics
Customizing plot charts
2nd Y axis and shadows
Example #23 - Customizing plot charts

Since release 1.27b it is possible to associate a picture (only GIF files are supported) to one data serie. This picture will replace the bubles while drawing a plot chart. First associate one picture to one serie calling the SetSerieSymbol function of the pData class. The title of the chart is written over the grap area using the drawTextBox function setting a transparency factor of 30%

Running this script will create a example22.png file in the current directory.

Output :


Source code :
  1. <?php  
  2.  // Standard inclusions  
  3.  include("pChart/pData.class");  
  4.  include("pChart/pChart.class");  
  5.    
  6.  // Dataset definition  
  7.  $DataSet = new pData;  
  8.  $DataSet->AddPoint(array(60,70,90,110,100,90),"Serie1");  
  9.  $DataSet->AddPoint(array(40,50,60,80,70,60),"Serie2");  
  10.  $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May","Jun"),"Serie3");  
  11.  $DataSet->AddSerie("Serie1");  
  12.  $DataSet->AddSerie("Serie2");  
  13.  $DataSet->SetAbsciseLabelSerie("Serie3");  
  14.  $DataSet->SetSerieName("Company A","Serie1");  
  15.  $DataSet->SetSerieName("Company B","Serie2");  
  16.  $DataSet->SetYAxisName("Product sales");  
  17.  $DataSet->SetYAxisUnit("k");  
  18.  $DataSet->SetSerieSymbol("Serie1","Sample/Point_Asterisk.gif");  
  19.  $DataSet->SetSerieSymbol("Serie2","Sample/Point_Cd.gif");  
  20.   
  21.  // Initialise the graph     
  22.  $Test = new pChart(700,230);  
  23.  $Test->setFontProperties("Fonts/tahoma.ttf",8);  
  24.  $Test->setGraphArea(65,30,650,200);  
  25.  $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);  
  26.  $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);  
  27.  $Test->drawGraphArea(255,255,255,TRUE);  
  28.  $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);  
  29.  $Test->drawGrid(4,TRUE,230,230,230,50);  
  30.     
  31.  // Draw the title  
  32.  $Test->setFontProperties("Fonts/pf_arma_five.ttf",6);  
  33.  $Title = "Comparative product sales for company A & B  ";  
  34.  $Test->drawTextBox(65,30,650,45,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);  
  35.    
  36.  // Draw the line graph  
  37.  $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());  
  38.  $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  
  39.    
  40.  // Draw the legend  
  41.  $Test->setFontProperties("Fonts/tahoma.ttf",8);  
  42.  $Test->drawLegend(80,60,$DataSet->GetDataDescription(),255,255,255);  
  43.   
  44.  // Render the chart  
  45.  $Test->Render("example22.png");  
  46. ?>  
If you want to send the picture directly in a browser, replace the Render() command by Stroke().


Last updated on 05/15/2008