New to our community ?

Discover a world of possibilities! Join us and explore a vibrant community where ideas flourish and connections thrive.

One of Our Valued Members

Thank you for being part of our community. Your presence enriches our shared experiences. Let's continue this journey together!

Home php codes make a dynamic pi-chart with the help of PHP

make a dynamic pi-chart with the help of PHP


make a dynamic pi-chart with the help of dynamic pi chart

welcome back to, in this post we will see how to make a dynamic pi-chart with the help of PHP , MySQL and google charts. most of the time we need to show all reports in a graphical format, so we use pi-chart or other graphical charts.

In this tutorial we will write a PHP script which is helped to show programming language ratings on the pi -chart.
in the very first step we create a database with the name of pi, and also create a database table with the name of programming_languages, in this database we add 4 column (id, name,rating,staus).

-- phpMyAdmin SQL Dump
-- version 2.10.3
-- Host: localhost
-- Generation Time: Jan 12, 2019 at 07:37 AM
-- Server version: 5.0.51
-- PHP Version: 5.2.6


-- Database: `pi`

-- --------------------------------------------------------

-- Table structure for table `programming_languages`

CREATE TABLE `programming_languages` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`rating` int(5) NOT NULL,
`status` enum('1','0') character set utf8 collate utf8_unicode_ci NOT NULL default '1',

-- Dumping data for table `programming_languages`

INSERT INTO `programming_languages` VALUES (1, 'php', 15, '1');
INSERT INTO `programming_languages` VALUES (2, 'mysql', 5, '1');
INSERT INTO `programming_languages` VALUES (3, 'angular', 5, '1');
INSERT INTO `programming_languages` VALUES (4, 'python', 4, '1');
INSERT INTO `programming_languages` VALUES (5, 'perl', 10, '1');
INSERT INTO `programming_languages` VALUES (6, 'ruby', 9, '1');

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

now we create a database connection.

$connect = mysqli_connect("localhost", "root", "root", "pi"); 

in the index page we fetch programming language and ratings from database and show the record in pi chart .

//$query = "SELECT gender, count(*) as number FROM tbl_employee GROUP BY gender";
$query="SELECT name,rating FROM programming_languages WHERE status = '1' ORDER BY rating DESC"; 
$result = mysqli_query($connect, $query); 
<!DOCTYPE html> 
<title>Pie Chart by Google Chart API with PHP Mysql</title> 
<script type="text/javascript" src=""></script> 
<script type="text/javascript"> 
google.charts.load('current', {'packages':['corechart']}); 
function drawChart() 
var data = google.visualization.arrayToDataTable([ 
['Gender', 'Number'], 
while($row = mysqli_fetch_array($result)) 
echo "['".$row["name"]."', ".$row["rating"]."],"; 
var options = { 
// pieHole: 0.4 
var chart = new google.visualization.PieChart(document.getElementById('piechart')); 
chart.draw(data, options); 
<br /><br /> 
<div style="width:900px;"> 
<h3 align="center">PI CHART</h3> 
<br /> 
<div id="piechart" style="width: 900px; height: 500px;"></div>