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 #21 - Playing with backgrounds

Since release 1.27b it is now possible to customize backgrounds (Whole picture or only the graph area) by drawing gradient overlays. In this example we are filling the background calling drawGraphAreaGradient and specifying the target to be the background (Whole picture) TARGET_BACKGROUND. We are calling a second time this function specifying no target, by default it will be applyed to the graph area. The title of the graph is written calling the drawTextBox function specifying the box position to be on the bottom of the picture, the fill color, the text alignement. We're also applying a shading to the text content and setting the transparency of the background box to be of 30%.

Finally we're calling the AddBorder function to draw a 2px black border around the picture. This call must be done at the end of the chart drawing because it will resize the picture.

Output :

Source code :

  // Standard inclusions   

  // Dataset definition 
  $DataSet = new pData;

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

  // Draw the line chart

  // Draw the legend

  // Draw the title
  $Title = "Average Temperatures during the first months of 2008  ";

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

Last updated on 07/27/2008