Google org chart creation - Javascript Google Chart

Javascript examples for Google Chart:Org Chart

Description

Google org chart creation

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Org Chart Example</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['orgchart']}]}"></script> 
      <div id="chart_div" "></div> 
      <script type="text/javascript">
      google.setOnLoadCallback(drawChart);
      function drawChart() {//from w  w w . j  a v a  2s.  c o m
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('string', 'Parent');
        data.addRows([
          ['Mike', ''],
          ['Jim', 'Mike'],
          ['Alice', 'Mike'],
          ['Bob', 'Jim'],
          ['Carol', 'Jim'],
          ['Bob2', 'Alice'],
          ['Carol2', 'Alice']
        ]);
        var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
          google.visualization.events.addListener(chart, 'select', function(){
              var children=[]
              var selected=chart.getSelection()[0].row;
              function getChilds(index){
                  var childs=chart.getChildrenIndexes(index);
                  for(var i = 0; i < childs.length;i++){
                      children.push(data.getValue(childs[i],0))
                      getChilds(childs[i])
                  }
              }
              getChilds(selected)
              console.log(children)
          })
        chart.draw(data, {allowHtml:true});
      }

      </script>  
   </body>
</html>

Related Tutorials