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 #10 - Small "Fast Graphs"

It can be usefull to add small graphs on web pages tracking pages views or visitors per hour. You can use pChart to draw minimal pieces of charts. In this example Data are manualy set using the AddPoint() method of the pData class. The graph function called is drawLineGraph(). Running this script will create a SmallGraph.png file in the current directory.

Source code :
 <?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),"Serie1");
 $DataSet->AddAllSeries();
 $DataSet->SetAbsciseLabelSerie();
 $DataSet->SetSerieName("January","Serie1");

 // Initialise the graph
 $Test = new pChart(100,30);
 $Test->setFontProperties("Fonts/tahoma.ttf",8);
 $Test->drawFilledRoundedRectangle(2,2,98,28,2,230,230,230);
 $Test->setGraphArea(5,5,95,25);
 $Test->drawGraphArea(255,255,255);
  $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);   

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

 // Finish the graph
 $Test->Render("SmallGraph.png");
 ?>
 
If you want to send the picture directly in a browser, replace the Render() command by Stroke().


Last updated on 05/16/2008