Creating First Chart | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To begin with, let's create a simple chart that will visually depict the Weekly Sales of a fictitious shop. The sample data that we intend to plot can be tabularized as under: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Let's see how to use the FusionCharts PHP Class to plot this data into a Column3D chart: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php # Include FusionCharts PHP Class include('../Class/FusionCharts_Gen.php'); # Create Column3D chart Object $FC = new FusionCharts("Column3D","300","250"); # set the relative path of the SWF file $FC->setSWFPath("../FusionCharts/"); # Set chart attributes $strParam="caption=Weekly Sales;xAxisName=Week;yAxisName=Revenue;numberPrefix=$"; $FC->setChartParams($strParam); # add chart values and category names $FC->addChartData("40800","label=Week 1"); $FC->addChartData("31400","label=Week 2"); $FC->addChartData("26700","label=Week 3"); $FC->addChartData("54400","label=Week 4"); ?> <html> <head> <title>First Chart Using FusionCharts PHP Class</title> <script language='javascript' src='../FusionCharts/FusionCharts.js'></script> </head> <body> <?php # Render Chart $FC->renderChart(); ?> </body> </html> |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Let's analyze the steps involved in the above code:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Here is the Column 3D chart that our FusionCharts PHP Class renders: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Please go through the FusionCharts PHP Class API Reference section to know more about the functions used in the above code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How to change chart width and chart height? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When we declare an object of FusionCharts PHP Class the constructor is invoked. This constructor accepts the parameters that set the chart type, chart width and height. In the above code, the statement $FC = new FusionCharts("Column3D","300","250"); invokes the constructor which sets chart type as Column3D; width to 300 pixels and height to 250 pixels. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$FC = new FusionCharts("Column3D","450","350"); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How to change chart type? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
As we discussed above, chart type is also specified while declaring FusionCharts PHP Class object. $FC = new FusionCharts("Column3D","300","250"); To make a Pie Chart for our Weekly Revenue data, we just need to use Pie3D instead of Column3D while creating FusionCharts class object: $FC = new FusionCharts("Pie3D","300","250"); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To change chart type you can use any of the Chart Type names listed below : |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Please note that Chart Type Names - Line, MSLine and MSColumnLine3D from previous versions are changed to Line2D,MSLine2D and MSColumn3DLine (respectively). The old names are still applicable, though deprecated. We recommend you to use the new names. |