0

my php code is working and is giving an output.. but the pie chart (html part) is not working.. can anyone help me solve this??

<?php
$con=mysqli_connect("localhost","root","","test");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

if(isset($_POST['pie1']))
{
$to= $_POST['to'];

$from= $_POST['from'];
$query = mysqli_query($con,"SELECT COUNT(mrd),del FROM lr WHERE DATE(dod) >= '$from' and DATE(dod) <= '$to' and sno!=0 GROUP BY del");

while ($row=mysqli_fetch_array($query))
{
$pp=array();
$per=array();
$per[]=$row['del'];
$arr2=array_keys($row);
$arr1=array_values($row);
for ($i=0;$i<count($per);$i++)
{
 $pp[$i]=$row[0]/100;
echo "<pre>";
echo"$row[1]";
echo"\t";
echo"$row[0]";
echo"\t";
echo" $pp[$i]";
echo"<br>";
}
echo "<pre>";
$k=count($arr1);


echo "<pre>";
}

$query = mysqli_query($con,"SELECT COUNT(mrd),del FROM lr WHERE DATE(dod) >= '$from' and DATE(dod) <= '$to' and sno!=0 GROUP BY del");
while ($row=mysqli_fetch_array($query))
{
$kk=count($per);
echo"$kk";
for ($i=0;$i<$kk;$i++)
{


    $chart_array[$i]=array((string)$row[$i],intval($pp[$i]));
}


$data=json_encode($chart_array);
print_r($data);
}
}

?>


 <html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
     var data = new google.visualization.DataTable();
        data.addColumn("string", "Type of Delivery");
        data.addColumn("number", "% in no");

        data.addRows(<?php $data ?>);

        ]); 
      var options = {
           title: 'REPORT',
          is3D: 'true',
          width: 800,
          height: 600
        };

      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>
1
Contributor
1
Reply
12
Views
2 Years
Discussion Span
Last Post by Raadha
0

this code gives the output as

FORCEPS WITH RMLE 1 0.01
FTND WITH RMLE 20 0.2
LSCS 7 0.07
LSCS, GA 7 0.07
LSCS, SA 16 0.16
LSCS, TUBECTOMY 3 0.03
1[["1",0]]1[["20",0]]1[["7",0]]1[["7",0]]1[["16",0]]1[["3",0]]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.