Create Dynamic Google Pie Chart in PHP and MySQL

Hey Technoz, In this tutorial we are going to learn how to create dynamic google pie chart in php with additional feature of responsiveness. A pie chart presents data as a simple and easily understandable in picture. It can be an effective communication tool for visitors, because it represents data visually as a fractional part of a whole. Data comparison at a glance, enable user to make an immediate analysis or to understand information quickly. In this tutorial we are using google APi chart to improve simplicity and effectiveness of pie chart.

Creating database

To create dynamic google pie chart in php database need to create for storing the information about pie chart data

So lets create the database by using following queries. The following SQL creates piechart table which consist of  id, activity and time columns.

Dumping data for table ‘piechart’

Now lets insert some records by using following query.

First, To make it convenient, We will create a new PHP file for database configuration named  dbconfig.php that holds all configured parameters:

Create Dynamic Google Pie Chart in PHP

The following code piechart.php  is used to create dynamic google pie chart in PHP.


Eventually this code fetch the data from the database and create a table first to understand which dynamic data consists in pie chart.

To make the pie chart responsive it is important to set the height and width to ‘auto‘ in the option.(This is the simplest trick you will find all over the internet brings by technopoints)

To create donut pie chart set piehole: value in the option. The pieHole option should be set to a number between 0 and 1.

To create 3D pie chart set the is3D option to true

Now, You can see the glimpse of the above code in following snapshot:

Create Dynamic Google Pie Chart in PHP


Finally we have learn how to Create Dynamic Google Pie Chart in PHP and MySQL.

If you have any doubts regarding to this tutorial feel free to ask in the comment section below.

To catch even more knowledgeable and easy understandable tutorials please subscribe to get email notification.

Download Source Code

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.