简体   繁体   English

Google OrgChart-Google可视化

[英]Google OrgChart - Google Visualization

I have create a chart using orgchart similar to the following. 我已经使用orgchart创建了一个类似于以下内容的图表。 Chart generated through the data stored in mysql table (using php). 通过生成的图表将数据存储在mysql表中(使用php)。

在此处输入图片说明

My question is I want to display the depth level in each node along with other details. 我的问题是我想在每个节点中显示深度级别以及其他详细信息。 How to do that? 怎么做?

Example: Food -> Level 1 Vegetable and Meat -> Level 2 Vegetable 1, Vegetable 2 and Meat 1 -> Level 3

** There is api method ( data.getSelection.row ) to get the row (depth) of selected node. **有api方法( data.getSelection.row )获取选定节点的行(深度)。 But it always seems to give the index of selected node instead of the row of selected node. 但是它似乎总是给出选定节点的索引,而不是选定节点的行。 ** **

Not sure how you want to display them, but here is the idea I came up with: 不确定要如何显示它们,但这是我想到的想法:

      var depth = {}; // here we store node depths
      google.visualization.events.addListener(chart, 'ready', function () {
          for (var i = 0; i < data.getNumberOfRows(); i++) {
              depth[i] = 0; // we iniialize all in 0 depth
          }
          for (var i = 0; i < data.getNumberOfRows(); i++) { // for each row
              var childs = chart.getChildrenIndexes(i); // we check its descendants
              for (var child = 0; child < childs.length; child++) {
                  depth[childs[child]] += depth[i] + 1; // and add the parents depth+1
              }
          }
          console.log(depth) // here we have already all nodes depth
      });
      google.visualization.events.addListener(chart, 'select', function () {
          if (chart.getSelection().length > 0) {
              var node_row = chart.getSelection()[0].row;
              console.log(depth[node_row]) // now just show the depth of selected node
          }
      })
      chart.draw(data, {
          allowHtml: true
      });

Working fiddle: http://jsfiddle.net/a2zwqf1r/ 工作提琴: http : //jsfiddle.net/a2zwqf1r/

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

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