Many applications need graph implementation because its a good way of representing data. It is also very eye catching. So here,I am going to describe various ways of creating Graphs(simple to animated).

There are many sites which provide garphs. But here I am going to discuss about 2 libraries i.e. libchart and Fusion Chart.

The code can be downloaded from here. After downloading there is also a manual which describes each and every option. There are also some demo pages showing different types of charts i.e. Bar, Line, Pie, Multiple Bar, Multiple Line. These are the basic charts.

One has to just copy the whole class folder and the font folder and then include that class file( classes/ libchart.php ) in the page in which we want the graph. The font files path should be changed in file ( classes/view/test/Text.php ) in line 40 and 41. The base directory file path should be changed on line 37. Then in the page in which graph needs to be implemented, we have to place this code.

header(“Content-type: image/png”);/* This creates the chart as an image*/

$chart = new PieChart(500, 300);/* This calls the object for pie chart with specific width and height */

$dataSet = new XYDataSet();/* This creates a data set(Array) that will be mapped in the graph. */$dataSet->addPoint(new Point(“Bleu d’Auvergne”, 50));/* Creates the point in the pie */$dataSet->addPoint(new Point(“Tomme de Savoie”, 75));$dataSet->addPoint(new Point(“Crottin de Chavignol”, 30));$chart->setDataSet($dataSet);/* Bind the data set to the chart object */

$chart->setTitle(“Preferred Cheese”);/* Show title of the graph */$chart->render();/* Render the Graph */

The interesting thing is the calculation for the area occupied by each element is done by the class automatically. In the above for ‘ Bleu d’Auvergne ‘ the value is 50. So it will occupy ( 50/(50+75+30) ) * 100 % of the total pie chart.

Other chart can be easily prepared by this. There aree many samples available in the downloaded file.

One has to register there. No charges applied. Just give the name and email id and it will redirect to the download page. This contains demos with source code and a very useful manual.

Here one just have to include 2 class files present in (FusionChartsFree/Fusion_Charts/Code/PHP/Includes ) i.e. FC_Colors.php( For assigning different colors to the graph ) and FusionCharts.php( For creating animated graphs ). Then include the javascript file FusionCharts.js (FusionChartsFree/Fusion_Charts/FusionCharts ) and then include those swf files ( FusionChartsFree/Fusion_Charts/FusionCharts ) . These swf files are ShockWave flash files for animation.Fusion chart convert the xml data into the graph. So the data should be in xml format.