<?php
/* I load the pChart libraries which is in the class folder so that it can display a graph*/
include("class/pData.class.php");
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pPie.class.php");
include("class/pIndicator.class.php");
/*I create a new object containing my data for the chart */
$myData = new pData();
/*I lay out my data series to use for the chart and I set the vertical axis title with set Axis Name*/
$myData->addPoints(array(500,400,200,55,450,360,200,10,75,550,150),"Probe 3");
$myData->setSerieWeight("Probe 3",2);
$myData->setAxisName(0,"Number of males");
/*I indicate the horizontal data of the graph. There must be the same number as for my previous data series (logic)*/
$myData->addPoints(array("2013","2014","2015","2016","2017","2018","2019","2020","2021","2022","2023"),"Labels");
$myData->setSerieDescription("Labels","Years");
$myData->setAbscissa("Labels");
$myData->setPalette("Probe 3",array("R"=>0,"G"=>0,"B"=>255));
/* I create the image that will contain my previously created graphic */
$myPicture = new pImage(600,300,$myData);
/*I create a border in my image */
$myPicture->drawRectangle(2,2,599,299,array("R"=>0,"G"=>0,"B"=>255));
/* I indicate the title of my graphic, its positioning on the image and its font */
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(200,25,"Evolution of the number of male births in my little village",array("FontSize"=>14,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* I choose the background of my graph */
$myPicture->setFontProperties(array("FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6));
/* I determine the size of the graphic and its location in the image */
$myPicture->setGraphArea(60,40,550,280);
/* Parameters to draw the graph from the two abscissas */
$scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
$myPicture->drawScale($scaleSettings);
/* I insert on the right side the name of the author and the rights */
/* I draw my graph according to the previous parameters*/
/* I add red dots (plots) by displaying over the data */
/* I indicate the path where I want my image to be created */
$myPicture->autoOutput("images/evolution-male-births.png");
?>
Here are several examples to show you results that can be created with pChart: Examples
This library is available on www.pchart.net, it is used in particular by companies such as NASA, Sony or Airbus…