Subscribe For Free

Thursday, February 22, 2018

Google Pie Charts with PHP and MySQL

Populating pie charts with google api is one of the simplest way to do. here we are showing 
you a simple example to generate pie chart with real time data. fetching data from database table.
$DatabaseServer = "localhost";
$DatabaseUsername = "root";
$DatabasePassword = "root";
$DatabaseName = "demo";

$Connection = mysqli_connect($DatabaseServer, $DatabaseUsername, 
    $DatabasePassword, $DatabaseName);

if ($Connection === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());

$selectsql = "SELECT * FROM graph";
$result = mysqli_query($Connection, $selectsql);

    <script type="text/javascript" 
    <script type="text/javascript">
        google.charts.load('current', {'packages':['corechart']});

        function drawChart() {

          var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          <?php while($row = mysqli_fetch_array($result)){  ?>
             ["<?php echo $row['name']; ?>", <?php echo $row['count']; ?>],
          <?php } ?>

         var options = {
           title: 'My Daily Activities'

         var chart = new google.visualization.PieChart

         chart.draw(data, options);
<div id="piechart" style="width: 900px; height: 500px;"></div>
Run these queries in your database.
//Table structure for table `graph`
CREATE TABLE `graph` (
  `id` int(2) NOT NULL,
  `name` varchar(34) NOT NULL,
  `count` int(12) NOT NULL

//Dumping data for table `graph`

INSERT INTO `graph` (`id`, `name`, `count`) VALUES
(1, 'Work', 11),
(2, 'Eat', 2),
(4, 'Commute', 2),
(5, 'Watch TV', 2),
(6, 'Sleep', 7);


  1. Very useful information, i have a small doubt, how can we use php for search engine in website... Can you explain in another blog...

  2. thanks @abdhul, yes we will post an article on your suggestion soon.

  3. Hello @abdhul,
    This article might help you, check it once.

  4. We have update list of do-follow blog commenting sites for new visitors, we will update this list regular basis so share our list to your friends also.
    the bookmarking sites

  5. Our website also collect such a amat article like this website you can also check

  6. it's very helpful for js developer and Anular.

  7. Chest Freezer: They also let you store both big and oddly-shaped food items that would have no chance of being able to fit in your standard Freezer box on top of or next to your fridge.


  8. Want to know about the best TuTu Alternatives This article presents the top five best Tutu Helper alternatives for your Android and iOS TuTu Helper

  9. Trikalp laminates is a Laminate manufacturer company which is a hard and brittle sheets used to overlay on wooden furniture’s

  10. Block Board Manufacturer has become a block board paradise remaining ahead of all Asian countries in the region, and catering to the engineered wood related needs of the customers both within the country and abroad as well.

  11. Download 4Liker APK for Androi devices such as Smartphone or Tablet to get Facebook and Instagram auto likes on the posts you shared and increase the likes on your posts. instagram 4liker

  12. Corrugated Box Making Machine For safe and cheap packaging for transportation of goods, corrugated cardboard cartons have proven to be the most practical material of choice! This has increased their usage across almost every industry.

  13. E – Rickshaw Manufacturer in India An electric rickshaw offers a number of advantages with which it achieves greater preference as compared to other traditional vehicles used for short distance communication like an auto rickshaw or manually run rickshaw.

  14. Collection of modern office furniture in Melbourne. Adept Office supplies extensive range of office furniture in Melbourne. We also sell quality home computer furniture.

  15. Smart cards or HID access cards are plastic identity card exactly like the dimensions of the driver’s license or credit card. The depth of a HID entry card may fluctuate based. Access Card Cloning Service

  16. IOM Partners of Houston, TX is one of the foremost wordpress houston web design company that has exceptional skills in the area of designing bespoke websites with all the best navigable features and user engaging functionalities. It is the Numero Uno web design company in Texas with a difference, as it builds custom websites on the versatile WordPress platform.

  17. I am also associated with Goliath Cranes Manufacturers, EOT Cranes Manufacturers, by Pioneer Cranes is a leading Overhead Crane Manufacturers in India, and love to enjoy the stuff on the same as its rarely found on internet. Thanks again for writing such a good post.

  18. I am also associated with E Rickshaw Dealers, E Rickshaw Dealers, by Erickshaw Dealers is a leading E Rickshaw Dealers in India, and love to enjoy the stuff on the same as its rarely found on internet. Thanks again for writing such a good post.


  19. Alternative Aptoide App Stores are what have been most common these days. Gone are the days we depended upon the official app stores for our requirements of apps and games. aptoide ios

  20. Great Post Shared by you. Silverservice24x7 Best Cab Service Melbourne providing by Silverservice24x7 Book cabs now just by a call at 0452 622 391 or online booking is available at For more detail visit at

  21. I would like to read again your next write-ups.
    It was so nice article.
    Thanks for Sharing.


click it