want to use org chart to display hierarchical chart of program dependencies

20 views
Skip to first unread message

Morry Davis

unread,
Jul 13, 2017, 7:48:39 PM7/13/17
to Google Visualization API
Looking for options on how to do this. org chart as is doesn't work  because nodes have to be unique but as we know a function may have more than one parent I create the array correctly but only the first use of the node is displayed. Is there something more suited to do what I'm trying to achieve.
    <?php
        /*echo "Item sent from post " . $_POST['parent'];*/
        $node = $_POST['parent'];
        $GLOBALS['i']=0;
        $parent="";
 
        function buildBranch($node, $con, $parent) {

            $GLOBALS['branchcount']++;
            $sql="SELECT Child FROM Links WHERE Parent='$node' ORDER BY Child ASC";
             $branch = mysqli_query($con,$sql);
            while($row = mysqli_fetch_array($branch)) {
                $GLOBALS['i']++;
                 $GLOBALS['ROWS'][$GLOBALS['i']] = [$row['Child'],$node];
                buildBranch($row['Child'],$con, $node);
           
            }
 
        }

        include "connectDB.php";
        mysqli_select_db($con,"mapping_demo");
        $GLOBALS['ROWS'][$GLOBALS['i']] = [$node,""];
        $GLOBALS['prevNode'] = $node;
        buildBranch($node,$con,$parent);
 
        mysqli_close($con);
        $mySweetJSONString=json_encode($ROWS);
    ?> 
   <script type='text/javascript' src='https://www.google.com/jsapi'></script> 
   <script type='text/javascript'> 
    google.load('visualization', '1', {packages:['orgchart']});    
    google.setOnLoadCallback(drawChart);
   
    function drawChart() { 
     var data = new google.visualization.DataTable();
     var myArray = <?php echo "$mySweetJSONString"; ?>;
     data.addColumn('string', 'Node'); 
     data.addColumn('string', 'Parent'); 
     data.addRows(myArray);
 
     var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));

     chart.draw(data); 
    } 
   </script> 
Reply all
Reply to author
Forward
0 new messages