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
Overview  |  Screenshots  |  Download  |  Add-ons  |  Demonstration  |  Support  |  :: Documentation ::
Documentation Contents
Class definition
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 #26 - Playing with shadows and second Y axis

Since release 1.27d it is possible to draw shadows behind drawn pixels. Shadow can be added to any plot-drawn objects line lines and cubics. Use shadows with caution as this will add extra computing time to your charts. If you want to display rendered data on your web pages, I invite you to use the pCache class to speed up the processing time.

This example is showing how to display two data series with dedicated Y axis. Basic way to associate a data serie to one axis is to first add only the attached data series to the grapher using the AddSerie() function of the pData class and then invoke the drawScale() function of the pChart class. Before drawing the right scale, use the clearScale() function and remove the previously graphed series with the RemoveSerie() function of the pData class. Then add the remaining series using the AddSerie() function and compute the second Y axis calling the drawRightScale() function.

Shadows are activated calling the setShadowProperties() function. You must remove the shadow engine calling the clearShadow() when you've finished to draw your data series. If you forget to remove the shadow, you'll experience strange graphing effects.

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

Output :

Source code :
  // Standard inclusions   

  // Dataset definition 
  $DataSet = new pData;
  $DataSet->AddPoint(array("03 Oct","02 Oct","01 Oct","30 Sep","29 Sep","28 Sep","27 Sep"),"Serie3");
  $DataSet->SetSerieName("SourceForge Rank","Serie1");
  $DataSet->SetSerieName("Web Hits","Serie2");

  // Initialise the graph
  $Test = new pChart(660,230);

  // Prepare the graph area

  // Initialise graph area

  // Draw the SourceForge Rank graph
  $DataSet->SetYAxisName("Sourceforge Rank");

  // Clear the scale

  // Draw the 2nd graph
  $DataSet->SetYAxisName("Web Hits");

  // Write the legend (box less)

  // Write the title
  $Test->drawTitle(0,0,"SourceForge ranking summary",255,255,255,660,30,TRUE);

  // Render the picture
If you want to send the picture directly in a browser, replace the Render() command by Stroke().

Last updated on 10/03/2008