Display records from database using pie chart


<?php $con=mysqli_connect('localhost','root','root','pie_chart') or die(mysqli_connect_error());

   $query=mysqli_query($con,"select * from visitors") or die(mysqli_error($con));

 ?>




<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([
          ['country', 'Visits'],
          <?php

          while ($row=mysqli_fetch_assoc($query)) {
             
              echo "['".$row['country']."',".$row['vis']."],";

          }

           ?>
        ]);

        var options = {
          title: 'Visits from Various country',
          is3D:true,
        };

        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>

Comments

Popular posts from this blog

How to seperate character from string in php

How to Delete record using PHP Ajax

Uploads Only 10 files in month step by step