Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

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.
<?php
$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);
?>

<html>
<head>
    <script type="text/javascript" 
            src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
        google.charts.load('current', {'packages':['corechart']});
        google.charts.setOnLoadCallback(drawChart);

        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
         (document.getElementById('piechart'));

         chart.draw(data, options);
        }
    </script>
</head>
<body>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
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
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

//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);
Result:

16 comments:

  1. Lodha Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Codename Smart Buy Dombivali project, where life is evergreen is a Under-Construction project from the house of Lodha Group properties. Group properties brings you a new world of live comfortable location of Dombivali in Mumbai, where lifestyle at its best phase! Codename Smart Buy Dombivali offers competitively priced apartments to those looking for a stylish and classy lifestyle. Codename Smart Buy Dombivali gives high on connectivity and convenience as well. Codename Smart Buy is design by the best architect of India and also uses best construction material. Codename Smart Buy Dombivali is design as big town ship and also having commercial space that is best option of Business Purpose. Near Codename Smart Buy positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Codename Smart Buy is offers to a very good qualities and futures in whole life. such as to its a very good news because Dombivali is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  2. Lodha Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Lodha Codename Smart Buy Dombivali project, where life is evergreen is a Under-Construction project from the house of Lodha Group properties. Lodha Group properties brings you a new world of live comfortable location of Dombivali in Mumbai, where lifestyle at its best phase! Lodha Codename Smart Buy Dombivali offers competitively priced apartments to those looking for a stylish and classy lifestyle. Lodha Codename Smart Buy Dombivali gives high on connectivity and convenience as well. Lodha Codename Smart Buy is design by the best architect of India and also uses best construction material. Lodha Codename Smart Buy Dombivali is design as big town ship and also having commercial space that is best option of Business Purpose. Near Lodha Codename Smart Buy positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Lodha Codename Smart Buy is offers to a very good qualities and futures in whole life. such as to its a very good news because Dombivali is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  3. Lodha Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Lodha Codename Smart Buy Dombivali project, where life is evergreen is a Under-Construction project from the house of Lodha Group properties. Lodha Group properties brings you a new world of live comfortable location of Dombivali in Mumbai, where lifestyle at its best phase! Lodha Codename Smart Buy Dombivali offers competitively priced apartments to those looking for a stylish and classy lifestyle.

    ReplyDelete
  4. I guess you are the student searching for map skills student login and hence landed on this page. So,I won’t dissatisfy and make your search unworthy. The map skills portal is an online website designed with the motive of providing an interactive learning program for students.
    click here

    ReplyDelete
  5. Adhiraj Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Adhiraj Capital City Oreka Kharghar project, where life is evergreen is a New Launch project from the house of Adhiraj Group properties. Group properties brings you a new world of live comfortable location of Kharghar in Navi Mumbai, where lifestyle at its best phase! Adhiraj Capital City Oreka Kharghar offers competitively priced apartments to those looking for a stylish and classy lifestyle. Adhiraj Capital City Oreka Kharghar gives high on connectivity and convenience as well. Adhiraj Capital City Oreka is design by the best architect of India and also uses best construction material. Adhiraj Capital City Oreka Kharghar is design as big town ship and also having commercial space that is best option of Business Purpose. Adhiraj Capital City Oreka positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Adhiraj Capital City Oreka is offers to a very good qualities and futures in whole life. such as to its a very good news because Kharghar is situated to in heart of Navi Mumbai, where we know about in a good natural thing.

    ReplyDelete
  6. https://www.thelaunch.in/codenamebigleap/
    Poddar Housing is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Codename Big Leap project, where life is evergreen is a New Launch project from the house of Poddar Housing properties. Group properties brings you a new world of live comfortable location of Kalyan in Mumbai, where lifestyle at its best phase! Codename Big Leap offers competitively priced apartments to those looking for a stylish and classy lifestyle. Codename Big Leap gives high on connectivity and convenience as well. Codename Big Leap is design by the best architect of India and also uses best construction material. Codename Big Leap is design as big town ship and also having commercial space that is best option of Business Purpose. Near Codename Big Leap positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Codename Big Leap is offers to a very good qualities and futures in whole life. such as to its a very good news because Kalyan is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  7. https://www.thelaunch.in/adhirajoreka/
    Adhiraj Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Adhiraj Oreka Kharghar project, where life is evergreen is a New Launch project from the house of Adhiraj Group properties. Group properties brings you a new world of live comfortable location of Kharghar in Navi Mumbai, where lifestyle at its best phase! Adhiraj Oreka Kharghar offers competitively priced apartments to those looking for a stylish and classy lifestyle. Adhiraj Oreka Kharghar gives high on connectivity and convenience as well. Adhiraj Oreka is design by the best architect of India and also uses best construction material. Adhiraj Oreka Kharghar is design as big town ship and also having commercial space that is best option of Business Purpose. Near Adhiraj Oreka positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Adhiraj Oreka is offers to a very good qualities and futures in whole life. such as to its a very good news because Kharghar is situated to in heart of Navi Mumbai, where we know about in a good natural thing.

    ReplyDelete
  8. http://thelaunch.in/birlavanya/
    Birla Group - who delivers the best residential real estate properties based on affordable payment plans coming up with the new luxurious project Birla Vanya at Shahd near Kalyan, Mumbai situated in the convenient location Mumbai.The total project area of Birla Vanya Mumbai is spreaded across the region where the whole township is getting ready for their homebuyers looking for the luxurious homes Birla Vanya Shahad kalyan,Mumbai is going to offer 1, 1.5, 2 and 3 BHK spacious apartments integrated with the number of class amenities that gives the best living structure for the lifestyle.The main attraction of these project developed by Birla Group providing apartments surrounded with the natural touch which created the balanced lifestyle to live. The homebuyers looking for the best home structure with all the world class amenities can go with Birla Vanya where they can enjoy the best connectivity throughout the thane and the nearby places. The property rates of Mumbai is increasing day by day where Birla Group is providing afforable homes to their homebuyers where they can enjoy the seamless lifestyle with their loved ones. There are the many reasons one can buy their dream home at Birla Vanya Mumbai, where social infrastructure and excellent connectivity is provided by the tower Birla Vanya Kalyan,Mumbai.

    ReplyDelete
  9. http://thelaunch.in/wadhwawinwin/
    The Wadhwa Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Wadhwa Winwin Mulund Mumbai project, where life is evergreen is a New Lunch project from the house of The Wadhwa Group properties. The Wadhwa Group properties brings you a new world of live comfortable location of Mulund in Mumbai, where lifestyle at its best phase! Wadhwa Winwin Mulund Mumbai offers competitively priced apartments to those looking for a stylish and classy lifestyle. Wadhwa Winwin Mulund Mumbai gives high on connectivity and convenience as well. Wadhwa Winwin Mulund Mumbai is design by the best architect of India and also uses best construction material. Wadhwa Winwin Mulund Mumbai is design as big town ship and also having commercial space that is best option of Business Purpose. Near Wadhwa Winwin Mulund Mumbai positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Wadhwa Winwin Mulund Mumbai is offers to a very good qualities and futures in whole life. such as to its a very good news because Mulund is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  10. https://www.thelaunch.in/kalpataruelitusmulund/#about
    The Kalpataru Mulund is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Kalpataru Elitus Mulund project, where life is evergreen is a New Lunch project from the house of The Kalpataru Mulund properties. The Kalpataru Mulund properties brings you a new world of live comfortable location of Mulund West in Mumbai, where lifestyle at its best phase! Kalpataru Elitus Mulund offers competitively priced apartments to those looking for a stylish and classy lifestyle. Kalpataru Elitus Mulund gives high on connectivity and convenience as well. Kalpataru Elitus Mulund is design by the best architect of India and also uses best construction material. Kalpataru Elitus Mulund is design as big town ship and also having commercial space that is best option of Business Purpose. Near Kalpataru Elitus Mulund positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Kalpataru Elitus Mulund is offers to a very good qualities and futures in whole life.

    ReplyDelete
  11. https://www.thelaunch.in/maverickwishvas/
    The Maverick Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Maverick Wishvas Bhandup Mumbai project, where life is evergreen is a New Lunch project from the house of The Maverick Group properties. The Maverick Group properties brings you a new world of live comfortable location of Bhandup in Mumbai, where lifestyle at its best phase! Maverick Wishvas Bhandup Mumbai offers competitively priced apartments to those looking for a stylish and classy lifestyle. Maverick Wishvas Bhandup Mumbai gives high on connectivity and convenience as well. Maverick Wishvas Bhandup Mumbai is design by the best architect of India and also uses best construction material. Maverick Wishvas Bhandup Mumbai is design as big town ship and also having commercial space that is best option of Business Purpose. Near Maverick Wishvas Bhandup Mumbai positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Maverick Wishvas Bhandup Mumbai is offers to a very good qualities and futures in whole life. such as to its a very good news because Bhandup is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  12. https://www.thelaunch.in/adhirajcodenamecountdown/
    The Adhiraj Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Adhiraj Codename Countdown Kharghar project, where life is evergreen is a New Lunch project from the house of The Adhiraj Group properties. The Adhiraj Group properties brings you a new world of live comfortable location of Kharghar West in Mumbai, where lifestyle at its best phase! Adhiraj Codename Countdown Kharghar offers competitively priced apartments to those looking for a stylish and classy lifestyle. Adhiraj Codename Countdown Kharghar gives high on connectivity and convenience as well. Adhiraj Codename Countdown Kharghar is design by the best architect of India and also uses best construction material. Adhiraj Codename Countdown Kharghar is design as big town ship and also having commercial space that is best option of Business Purpose. Near Adhiraj Codename Countdown Kharghar positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Adhiraj Codename Countdown Kharghar is offers to a very good qualities and futures in whole life. such as to its a very good news because Kharghar West is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  13. https://www.thelaunch.in/codenameconvenientwadala/
    The Labdhi Lifestyle is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Codename Convenient Wadala project, where life is evergreen is a New Lunch project from the house of The Labdhi Lifestyle properties. The Labdhi Lifestyle properties brings you a new world of live comfortable location of Wadala in Mumbai, where lifestyle at its best phase! Codename Convenient Wadala offers competitively priced apartments to those looking for a stylish and classy lifestyle. Codename Convenient Wadala gives high on connectivity and convenience as well. Codename Convenient Wadala is design by the best architect of India and also uses best construction material. Codename Convenient Wadala is design as big town ship and also having commercial space that is best option of Business Purpose. Near Codename Convenient Wadala positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Codename Convenient Wadala is offers to a very good qualities and futures in whole life. such as to its a very good news because Wadala is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete
  14. https://www.thelaunch.in/godrejrkschembur/
    The Godrej Group is a real estate company known for its expertise in ensuring best quality and mastery over the design area. Godrej RKS Chembur project, where life is evergreen is a New Lunch project from the house of The Godrej Group properties . The Godrej Group properties brings you a new world of live comfortable location of Chembur in Mumbai, where lifestyle at its best phase! Godrej RKS Chembur offers competitively priced apartments to those looking for a stylish and classy lifestyle. Godrej RKS Chembur gives high on connectivity and convenience as well. Godrej RKS Chembur is design by the best architect of India and also uses best construction material. Godrej RKS Chembur is design as big town ship and also having commercial space that is best option of Business Purpose. Near Godrej RKS Chembur positioned in close proximity to major IT campuses, your work place could be just a stone’s throw away. Godrej RKS Chembur is offers to a very good qualities and futures in whole life. such as to its a very good news because Chembur is situated to in heart of Mumbai, where we know about in a good natural thing.

    ReplyDelete

More Posts

Subscribe Us

FOLLOW