简体   繁体   English

google组织结构图:无法显示组织结构图

[英]google organisation chart : Unable to display the organisation chart

Here is my database snap: link 这是我的数据库快照: 链接
Here is my code: 这是我的代码:

<?php
 $db=mysqli_connect("localhost","root","","organisation"); //db connection
 $query=mysqli_query($db, "SELECT name,below_whom FROM org"); //fetch data
 if($query){
 $data=[];
 while($org_data=mysqli_fetch_assoc($query)){
 $data []= [$org_data["name"],$org_data["below_whom"]]; //syntax of 
 associative array = $variable["value"]
 }
 #echo '<pre>'; print_r($data); echo '</pre>';
 }
 else {
 "Error".mysqli_error();
}
?>
<html>
<head></head>
<body>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'name');
data.addColumn('string', 'below_whom');
data.addColumn('string', 'ToolTip');
data.addRows(<?php echo json_encode($data); ?>);
var chart = new google.visualization.OrgChart(document.getElementById('chart_div')); 
chart.draw(data, {allowHtml:true});
}
</script>
<div id="chart_div"></div> 
</body>
</html>

I have been going through the documentation for quite sometime now and I am still clueless. 我已经阅读文档已有一段时间了,但我仍然一无所知。 I guess error is somewhere near addRows but I'm unable to trace it. 我猜错误在addRows附近,但是我无法追踪。

It seems to me that there is no issue with your code, however the issue is in your data. 在我看来,您的代码没有问题,但是问题出在您的数据中。 Your queried data will be like this: 您查询的数据将如下所示:

|name   |below_whom|
|-------|----------|
|Pratik |          |
|-------|----------|
|Q      |FTA       |
|-------|----------|

So you see, the "Q" has "FTA" as the boss, but google organization chart could not find "FTA". 因此,您会看到,“ Q”以“ FTA”作为老板,但是Google组织结构图找不到“ FTA”。 If you change "FTA" to "Pratik", you will see magic happens. 如果将“ FTA”更改为“ Pratik”,将会看到魔术发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM