Saturday, 20 June 2020

Graph

Hi All,
See how graph can be drawn using Google tools.

----------------------------------------------
Table structures

CREATE TABLE IF NOT EXISTS `graphdata` (
  `id` int(11) NOT NULL,
  `percentage` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `graphdata`
--

INSERT INTO `graphdata` (`id`, `percentage`) VALUES
(1, 80),
(2, 60);
----------------------------------------------------------------------

<!DOCTYPE html>
<!-- Website template by freewebsitetemplates.com -->
<html>
<head>
<meta charset="UTF-8">
<title> PROJECT MANAGEMENT</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<?php
include'dbconnect.php';
$sql="delete from graphdata";
    mysql_query($sql);

$sql="select distinct(pgid) as pgids from members";
    $data=mysql_query($sql);
    while($row=mysql_fetch_array($data))
    {
         $id=$row['pgids'];
echo $id."<br>";
$qr="select percentage from members where pgid='$id'";
echo $qr;
$sum=0;
$count=0;
$data1=mysql_query($qr);
$percentage=0;
         while($row1=mysql_fetch_array($data1))
         {
          $count=$count+1;
  $percentage=$percentage+$row1['percentage'];

         }
$sum=$sum+$percentage;
         $avg=$sum/$count;
mysql_query("insert into graphdata values('$id','$avg')");





    }





?>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<body>

<h1>My Web Page</h1>

<div id="piechart"></div>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

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

// Draw the chart and set the chart values
function drawChart() {
var data = google.visualization.arrayToDataTable([
  ['Id', 'Percentage']
<?php
$sql="select * from graphdata,proreg where graphdata.id=proreg.id";
    $data=mysql_query($sql);
    while($row=mysql_fetch_array($data))
    {
         $id=$row['name'];
$avg=$row['percentage'];
?>
 
  <?php
  echo ",['$id', $avg]";
}
  ?>

]);

  // Optional; add a title and set the width and height of the chart
  var options = {'title':'My Average Day', 'width':550, 'height':400};

  // Display the chart inside the <div> element with id="piechart"
  var chart = new google.visualization.PieChart(document.getElementById('piechart'));
  chart.draw(data, options);
}
</script>

</body>
</html>