dongwen1871 2018-06-12 17:52
浏览 102
已采纳

谷歌组织结构图:无法显示组织结构图

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.

  • 写回答

1条回答 默认 最新

  • douyao1856 2018-06-12 18:12
    关注

    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". If you change "FTA" to "Pratik", you will see magic happens.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程