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
Line graph
Cubic curve graph
Bar Graph
Stacked Bar Graph
Overlay Bar graph
Line + Area
Limits graph
Filled line graph
Filled cubic graph
Radar graph
Basic Pie graph
Exploded Pie graph
3D Pie graph
Scatter charts
Advanced Examples
Example #25 - Scatter charts

Like the pie charts, scatter charts require a special use of the pData class.

To draw a scatter plot you need to define at least two data serie. In this exemple Serie1/Serie2 will be drawn as line. Data are filled using some maths functions (cos/sin) to render circles. We'll keep the scaling dynamic.

Before rendering a scatter chart you must invoke the drawXYScale() function that will create both X and Y axis. By default, min/max values will be retrieved from the series, anyway you can fix the values while calling the setFixedScale function (not shown in this example) : We can creating a box (-25,25)-(25,25) with 5 vertical and horizontal divisions.

To draw the line scatter chart we are calling the drawXYGraph function specifying the series name and the 1st palette color.

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

Source code :
  // Standard inclusions   

  // Dataset definition 
  $DataSet = new pData;

  // Compute the points

  $DataSet->SetSerieName("Trigonometric function","Serie1");
  $DataSet->SetXAxisName("X Axis");
  $DataSet->SetYAxisName("Y Axis");

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

  // Prepare the graph area

  // Draw the chart

  // Draw the title
  $Title = "Drawing X versus Y charts trigonometric functions  ";

  // Draw the legend

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

Last updated on 09/19/2008