i want create google org chart dynamic using mysql and php . My code is able to fetch the data from database but it do not show the tree. Please help me

67 views
Skip to first unread message

Jitendra Kurmi

unread,
Jan 28, 2018, 6:41:41 AM1/28/18
to Google Visualization API
<?php
$connect = mysqli_connect("localhost", "root", "123456", "testing");
$query="select uniqueid, managerid from employees";
/*
# Collect the results
while($obj = mysql_fetch_object($query)) {
    $arr[] = $obj;
}

# JSON-encode the response
$json_response = json_encode($arr);

// # Return the response
echo $json_response;
*/
$result = mysqli_query($connect, $query);  
?>
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript' src='jquery-1.6.2.min.js'></script>
<script type='text/javascript'>
google.load('visualization', '1', { packages: ['orgchart'] });
google.setOnLoadCallback(drawChart);
function drawChart()  
           {  
                var data = google.visualization.arrayToDataTable([  
                          ['UniqueId', 'ManagerId'],  
                         
<?php  
                          while($row = mysqli_fetch_array($result))  
                          {  
                              
  echo "['".$row[1]."', ".$row[0]."],"; 
  
                          }  
                          ?>   
                     ]);  
            var data = new google.visualization.DataTable(jsonData); 
        // For each orgchart box, provide the name, manager, and tooltip to show.
        data.addRows([
           
            var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
             chart.draw(data, { allowHtml: true });
          }
</script>

</head>
<body>
<div id="chart_div"></div>
</body>
</html>
------------------------------------------------
database table name employees
UniqueId                  ManagerId             Name
1                                    0                       ABC
2                                     1                     DEF
3                                    1                       GHI
4                                     2                       JKL
5                                     2                       MNO
Reply all
Reply to author
Forward
0 new messages