wrong percentage

21 views
Skip to first unread message

Tal Parag

unread,
Jan 26, 2021, 1:23:40 PM1/26/21
to Google Visualization API
hey i really need some help please , i am trying to make pie chart from data base i have but it looks like i am doing something wrong i suppose to get 50% in Female and 50% in Male but i got this like parts is missing and i can get whats wrong i can really use some helppppp
attaching the code in here

<?php 
require('database.php');
$connect = mysqli_connect("localhost","root", " ","servername");?>
<?php 
global $database;
$query ="SELECT Gender,count(*) as Number FROM users GROUP BY Gender";
$result=$database->query($query);

?>



<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<meta http-equiv="x-UA-compatibile" content="ie-edge">

<title>Data</title>

    <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([
            ['Female','Male'],
            
          <?php
         while($chart =mysqli_fetch_assoc($result))
         {
             echo"['".$chart['Gender']."','".$chart['Number']."'],";
         }
         
          ?>
        ]);

        var options = {
          title: 'who likes are websit better Female or Male?',
          
          
        };

        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>

pie wrong.png
Reply all
Reply to author
Forward
0 new messages