Google Chart using Codeigniter

We know that Google chart basically displays different statistical data on different chart types such as column chart, bar chart, line chart, pie chart etc. You can have a look at the URL for more information.

You can check the tutorial which shows year value in yyyy format

You can integrate Google chart with any server side technology but here I will show you how to integrate Google chart with Codeigniter. This tutorial shows step by step so that we can understand how it happens. It displays the data for Company Performance for last five years in bar(column) chart. You can also use other charts for any purpose. In this example I have used data coming from database. You can change the source of data as per your requirements.

If you have any query please feel free to leave a comment.

PHP 5.6
Codeigniter 2.2.0
Knowledge of Codeigniter
Apache http server
Netbeans 7.4
MySQL 5.5

Final Output

When Chart rendered on view

Google chart using Codeigniter

When you mouse hover on Chart slices

Google chart using Codeigniter

Now we will see how it happens step by step.

Step 1. Create php project called “ci”. Delete index.php file from the newly created project.

Step 2. Copy extracted files from into the created project in Netbeans.

Step 3. Go to location ci/application/config/database.php file and change database parameter values for below parameters

Step 4. Create a MySQL table in “cdcol” database

Step 5. Dump some values into database table – performance

Step 6. Go to ci/application/config/autoload.php and modify parameter values as shown below

Step 7. Create a model file chartmodel.php under ci/application/models directory with the below source code

Step 8. Create a controller file chartcontroller.php under ci/application/controllers with the following source code

Step 9. Create a view file chart.php under ci/application/views

Step 10. Modify file ci/application/config/routes.php file

Step 11. If everything is fine then run the application. You will get the output in the browser.

That’s all. Thanks for reading.

8 Replies to “Google Chart using Codeigniter”

  1. work good but I do not know how to customize the chart.. I want to change the 2k with a text every column but i dont know how…

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.