## FusionCharts PHP Class API > 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:
Week | Previous Month (sales)
Week 1 | $40800
Week 2 | $31400
Week 3 | $26700
Week 4 | $54400
Let's see how to use 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: We include FusionCharts_Gen.php in the program. This file contains FusionCharts PHP Class codes. include('../Class/FusionCharts_Gen.php'); We create a Column3D chart object. $FC = new FusionCharts("Column3D","300","250"); 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/"); We store all desired chart attributes in the $strParam variable and set chart attributes using setChartParams() function. $strParam="caption=Weekly Sales;xAxisName=Week;yAxisName=Revenue;numberPrefix=$"; $FC->setChartParams($strParam); 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"); Finally, we include FusionCharts.js - FusionCharts JavaScript Embedding Class. And display the chart using renderChart() function. $FC->renderChart();
Here is the Column 3D chart that our FusionCharts PHP Class renders:
Please go through 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 sets 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. Hence, we can use the constructure to set the desired dimension of our charts. Let's set our chart's dimension to 450 x 350 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 :
Chart Type Name | Description
Column2D | Single Series Column 2D Chart
Column3D | Single Series Column 3D Chart
Line2D | Single Series Line Chart
Pie3D | Single Series Pie 3D Chart
Pie2D | Single Series Pie 2D Chart
Bar2D | Single Series Bar 2D Chart
Area2D | Single Series Area 2D Chart
Doughnut2D | Single Series Doughnut 2D Chart
Doughnut3D | Single Series Doughnut 3D Chart
MSColumn3D | Multi-Series Column 3D Chart
MSColumn2D | Multi-Series Column 2D Chart
MSArea2D | Multi-Series Area 2D Chart
MSLine2D | Multi-Series Line Chart
MSBar2D | Multi-Series Bar 2D Chart
MSBar3D | Multi-Series Bar 3D Chart
StackedColumn2D | Stacked Column 2D Chart
StackedColumn3D | Stacked Column 3D Chart
StackedBar2D | Stacked Bar 2D Chart
StackedBar3D | Stacked Bar 3D Chart
StackedArea2D | Stacked Area 2D Chart
MSStackedColumn2D | Multi-Series Stacked Column 2D Chart
Bubble | Multi-series Bubble Chart
Scatter | Multi-Series Scaller Chart
ScrollColumn2D | Multi-Series Column 2D Scroll Chart
ScrollLine2D | Multi-Series Scroll Line 2D Scroll Chart
ScrollArea2D | Multi-Series Scroll Area 2D Scroll Chart
ScrollStackedColumn2D | Scroll Stacked Column 2D Scroll Chart
MSCombi3D | Combination Single Y-Axis 3D Chart
MSCombi2D | Combination Single Y-Axis Chart
MSColumn3DLine | Combination Single Y-Axis Chart (Column 3D + Line)
MSCombiDY2D | Combination Dual Y-axis 2D Chart
MSColumn3DLineDY | Combination Dual Y-Axis Chart (Column 3D + Line)
StackedColumn3DLineDY | Stacked Combination Column 3D Line Dual Y-Axis Chart
ScrollCombi2D | Scroll Combination 2D Single Y-Axis Scroll Chart
ScrollCombiDY2D | Scroll Combination Dual Y-Axis 2D Scroll Chart
MSStackedColumn2DLineDY | Combination Multi-Series Stacked Column 2D-Line Dual Y-Axis Chart
Grid | Single Series Grid Chart
Please note that Chart Type Names - Line, MSLine and MSColumnLine3D from previous version are change to Line2D, MSLine2D and MSColumn3DLine (respectively). The old Names ares still applicable, though depricated. We recommned to use the new Names.