Let's analyze the steps involved in the above code:
- We include FusionCharts_Gen.php in the program. This file contains FusionCharts PHP Class codes.
include('../Class/FusionCharts_Gen.php');
- We create a Grid chart object.
$FC = new FusionCharts("grid","300","200");
The constructor of FusionCharts PHP Class is invoked and it initializes chart type, chart width and chart height properties of the object.
- Next, we set relative path to the chart SWF files using setSwfPath() function. This is the path from which we load the chart SWF files.
$FC->setSWFPath("../FusionCharts/");
- Hereby, we use setGridParams() to set grid chart parameters(attributes) (Note that for Grid chart it is necessary to use this function instead of setChartParam() or setChartParams() . In the following line, we set font face and font size of the grid. The two attributes are separated by delimiters.
$FC->setGridParams("baseFont=vardana;baseFontSize=12");
- Then, we set to show the grid values as percentage.
$FC->setGridParams("showPercentValues=1");
- Next, we set background color of alternate data rows.
$FC->setGridParams("alternateRowBgColor=EAECEF");
- We now set number of data items that we want to display in one particular page. We set no. of items per page to four. In the following chart, the first page then displays four data and the next page displays the remaining three data items.
$FC->setGridParams("numberItemsPerPage=4");
- Now, we provide chart data with addChartData() function. We pass the value first and then, the category name against each value as a parameter i.e., label=Week 1 etc.
$FC->addChartData("40800","label=Week 1");
$FC->addChartData("31400","label=Week 2");
$FC->addChartData("26700","label=Week 3");
$FC->addChartData("54400","label=Week 4");
$FC->addChartData("88544","label=Week 5");
$FC->addChartData("22544","label=Week 6");
$FC->addChartData("65548","label=Week 7");
- Finally, we include FusionCharts.js - FusionCharts JavaScript Embedding Class and
- Display the chart using renderChart() function.
$FC->renderChart();
|