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
pChart.class
pData.class
pCache.class
FAQ
Digging with pChart
Basic Examples
Advanced Examples
Documentation

This documentation has been last updated on 06/18/2008.

pChart - a chart drawing library

Thank you for using pChart, we hope that you'll find the answer to your questions in this documentation. If not, feel free to use the dedicated sourceforge forum and tracker.
Drawing a chart can be cut in 3 parts : First, get access to the data and prepare it to be graphed ( you can use the pData class to help ). Second, prepare the graph design : rounded corners, freaky background, drawing area and then draw the chart! Last step, put some labels, title and legends. Your chart can now be saved in a web server folder or sent directly to the client browser.

Using the library

This class can be invoked for realtime picture drawing or cron/scheduled tasks. Rendering a graph is CPU consuming, we recomment that all static graphs ( or with a renewal interval of more than 10 minutes ) should be computed from a cron job, this also apply to web sites serving a lot of page views.

pChart is using the GD library to create pictures. You must compile the GD library with the freetype extension when installing PHP on a linux server. On windows operating system you must add the GD extension in your php.ini file. GD support is a mandatory prerequisite and cannot be overriden. You can use the following tutorial if you don't know how to install it on a linux server.
If you plan to use pChart on a production web service, keep an eye on project updates & progress list. We'll try to focus on increasing the graphical render speed.
A section of this documentation is dedicated on how to use pChart to render scheduled jobs ( windows & linux )

This graph is a simple -naked- rendering using the pChart library:

   <?php
   // Standard inclusions   
   include("pChart/pData.class");
   include("pChart/pChart.class");

   // Dataset definition 
   $DataSet = new pData;
   $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7));
   $DataSet->AddSerie();
   $DataSet->SetSerieName("Sample data","Serie1");

   // Initialise the graph
   $Test = new pChart(700,230);
   $Test->setFontProperties("Fonts/tahoma.ttf",10);
   $Test->setGraphArea(40,30,680,200);
   $Test->drawGraphArea(252,252,252);
   $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
   $Test->drawGrid(4,TRUE,230,230,230,255);

   // Draw the line graph
   $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
   $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

   // Finish the graph
   $Test->setFontProperties("Fonts/tahoma.ttf",8);
   $Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);
   $Test->setFontProperties("Fonts/tahoma.ttf",10);
   $Test->drawTitle(60,22,"My pretty graph",50,50,50,585);
   $Test->Render("Naked.png");
   ?>
  
Icons embeding the documentation are created and released by http://www.famfamfam.com/lab/icons/silk/ under the GNU 2.5 license. The javascript syntaxhighlighter library used to display PHP & JS code in this documentation is released under the GNU license.

Last updated on 06/18/2008