Zend Framework is a cluster of professional PHP packages that can be used to develop web applications and services using PHP 5.6+. It provides 100% object oriented code using a broad spectrum of language features.
One chart type can’t be used for visualising all types of data. FusionCharts offers a wide range of charts to choose from, depending on the type of data to be plotted and the type of analysis to be done. The package includes basic charts like the column chart, pie chart, doughnut chart, and so on; domain-specific power charts like the logarithmic charts, spline charts, error charts, and so on; gauges and widgets like the angular gauge, bulb gauge, thermometer gauge, and funnel and pyramid charts, and so on; and maps for all continents, major countries, and all US states.
FusionCharts works well across all browsers (including older ones like IE6) and has some pretty cool and useful features like client-side image export, events, themes, annotations, etc.
Without much ado then, let’s get started on how we can use the Zend Framework with FusionCharts for creating charts.
We’ll first list down the components that we need for creating charts. Here’s what we’ll require:
- XAMPP (Server): We are going to use the XAMPP server for this tutorial. You can use any other server that supports PHP and its frameworks like the MAMP server, the AMPPS server, etc. You can download XAMPP from here; it is available across all major platforms including Windows, OS X, and Linux.
- Zend Framework: Zend uses Composer as its package dependency manager. You can install Zend using the composer command given below:
1$ composer require zendframework/zendframework
Note:To know more about installing Zend and its packages, click here.
- FusionCharts: You can download the latest version of FusionCharts Suite XT from here. Alternately, you can also install it using the npm or bower package managers, using the commands given below:
12npm install fusionchartsnpm install fusionmaps
12bower install fusionchartsbower install fusionmaps
FusionCharts also provides a dedicated PHP wrapper to create charts in PHP. You can download it from here.
Now, as we have our environment ready, let’s create a Zend skeleton application in which we will embed our chart. For this, we will use the Composer command given below:
$ composer create-project -s dev zendframework/skeleton-application path/to/install
This command will install an initial set of dependencies needed for our application and we can now start configuring our application using the steps given below.
Click here to read more about the skeleton application and details on how you can create one.
Step 1: Setting up the virtual host
In this step, we will define a virtual host for our application by adding the code given below in the httpd.conf file of our apache web server.
DocumentRoot /path/to/zend framework/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zend framework/public>
Require all granted
Once we have made the changes in our config file, we will save the file and restart the server. We will now start our zend skeleton application using this URL to verify we are on right path.
Step 2: Creating the PHP file
In this step, we will create a new PHP file, which will include our chart object. First, we will include the FusionCharts PHP wrapper in our file using the code given below:
// including FusionCharts PHP charts wrapper
<title>Creating charts in PHP with Zend and FusionCharts</title>
<!-- including FusionCharts core package files -->
<div id="chartContainer">Chart will render here!</div>
Next, we will create a chart object using the FusionCharts PHP wrapper class and append it in our PHP file.
// chart object
$columnChart = new FusionCharts("column3d", "zend-chart" , 600, 300, "chartContainer", "json",
// chart cosmetics and properties
"caption": "Quarterly Revenue",
"subCaption": "Last year",
"yAxisName": "Amount (In USD)",
// rendering the chart
To know more about creating the chart object, you can check out this developer documentation page on the FusionCharts website.
We have now created our PHP file that we will place inside the public folder of our server.
Step 3: Executing the PHP file
In this step, we will render the chart we created by executing the PHP file created in step 2 via the browser using this URL:
phpFileName is the name of the file you created; in our example, this will be
If you’ve followed all the directions given above properly, you should have a working chart as shown in the screenshot below:
If you see any errors in your code, click here to view the complete source code of the sample project we created for this tutorial.
If you are ever stuck or have any questions, feel free to drop a line at firstname.lastname@example.org. Happy to help!