<?php

 /* Your Database Name */

$dbname = 'wheredoctorsare';

/* Your Database User Name and Passowrd */



$username = 'root';

$password = 'root';



try {



      /* Establish the database connection */



      $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);



      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);





/* select all the weekly tasks from the table googlechart */



      $result = $conn->query("SELECT * FROM doctor_absentism where county='Isiolo'");



	  



      



      $rows = array();



      $table = array();



      $table['cols'] = array(







        // Labels for your chart, these represent the column titles.



        /* 



            note that one column is in "string" format and another one is in "number" format 



            as pie chart only required "numbers" for calculating percentage 



            and string will be used for Slice title



        */







        array('label' => 'County', 'type' => 'string'),



        array('label' => 'Maternity or sick leave', 'type' => 'number'),



		array('label' => 'In training', 'type' => 'number'),



		array('label' => 'Official mission', 'type' => 'number'),



		array('label' => 'Approved absence', 'type' => 'number'),

		

		array('label' => 'Gone to retrieve salary', 'type' => 'number'),



		array('label' => 'Not approved absence', 'type' => 'number'),



		array('label' => 'Not on shift', 'type' => 'number'),



		array('label' => 'All others', 'type' => 'number')







    );



        /* Extract the information from $result */



        foreach($result as $r) {







          $temp = array();







          // the following line will be used to slice the Pie chart







          $temp[] = array('v' => (string) $r['county']); 







          // Values of each slice







          $temp[] = array('v' => (string) $r['maternity_or_sick_leave']); 



		  $temp[] = array('v' => (string) $r['in_training']); 



		  $temp[] = array('v' => (string) $r['official_mission']); 



		  $temp[] = array('v' => (string) $r['approved_absence']); 

		  

		  $temp[] = array('v' => (string) $r['gone_to_retrieve_salary']); 

		  

		  $temp[] = array('v' => (string) $r['not_approved_absence']); 

		  

		  $temp[] = array('v' => (string) $r['not_on_shift']); 

		  

		  $temp[] = array('v' => (string) $r['all_others']); 

		  



          $rows[] = array('c' => $temp);



        }







    $table['rows'] = $rows;







    // convert data into JSON format



    $jsonTable = json_encode($table);



    echo $jsonTable;



    } catch(PDOException $e) {



        echo 'ERROR: ' . $e->getMessage();



    }



?>

<html>

  <head>

    <!--Load the Ajax API-->

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>

	<link href='http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic' rel='stylesheet' type='text/css'>

    <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(<?=$jsonTable?>);

      var options = {

           title: 'Reasons for absence',

          is3D: 'false',

          width: 800,

          height: 600

        };

      // Instantiate and draw our chart, passing in some options.

      // Do not forget to check your div ID

      var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));

      chart.draw(data, {title:"Reasons for absence",hAxis: {chartArea:{left:20,top:20,width:"100%",height:"100%"},title: "Number of doctors",titleTextStyle: {color: '#000'}},vAxis:{title:""},width: 670, height: 300,fontName:'Roboto',});

    }

    </script>

  </head>



  <body>

    <!--this is the div that will hold the pie chart-->

    <div id="chart_div"></div>

  </body>

</html>