Hi,
today i wanted to talk about a class that i have been using a lot lately and i have worked with it for the past months, called pChart. this class let you create charts from stream data. the class let you create line, curve, cake/basic pie, bar,stacked,radar, 3d pie,radar, and scatter charts, and in this list i’m sure i’m forgetting some of them. the process to create the chart is very simple
as you see in the graph, the process consist in get the data from some stream, something that there is not mentioning is that the data retrieved, if is not a csv that the class have inbuilt functions to parse it, you need to prepare it, ordering in a specific way depending the type of chart you are using (if is a line bar, you need to define the serie name’s for each axis and the values for it). after you have the data, set the style, as the background, the font type and size (it support ttf fonts) and the scale. and then you are ready to draw the chart, that the returned data can be printed to the user directly, of course first setting a image type stream with the header() function or write it in a file.
below, you can see some example code:
// Standard inclusions
include(“pChart/pData.class”);
include(“pChart/pChart.class”);
// Dataset definition
$DataSet = new pData; // initialize the data parser object
$DataSet->ImportFromCSV(“Sample/bulkdata.csv”,”,”,array(1,2,3),FALSE,0); //get the data input from a csv file
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName(“January”,”Serie1″);
$DataSet->SetSerieName(“February”,”Serie2″);
$DataSet->SetSerieName(“March”,”Serie3″);
$DataSet->SetYAxisName(“Average age”);
$DataSet->SetYAxisUnit(“µs”);
// Initialise the graph
$Test = new pChart(700,230); //setting the widht and height of the chart
$Test->setFontProperties(“Fonts/tahoma.ttf”,8); //the font used for the chart and the font size
$Test->setGraphArea(70,30,680,200); //the width, height, x and y position of the area where the graph will be drawn
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties(“Fonts/tahoma.ttf”,6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// 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(75,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties(“Fonts/tahoma.ttf”,10);
$Test->drawTitle(60,22,”example 1″,50,50,50,585);
$Test->Render(“example1.png”);
and this is the result
you can download the class from here, you can find documentation and the classes definition at here, and here several examples of how to create different types of graphs
i hope this help you in some way
.
Regards,
Shadow.








