javascript - Google Visualization Organizational Chart (Node Children) -
i have organizational chart many levels, image below taken part of it. try childs , sub childs of selected node, if "power business unit" node selected 3 childs , every single child same. got first level can't depth of tree provide number of loops reach last child.
1- how can last child in chart? how depth of tree?
2- there zoom in/zoom out toolbar or something, can add chart?
that code of drawing:
google.load('visualization', '1', { packages: ['table', 'orgchart'] }); google.setonloadcallback(drawchart); function drawchart() { var data = new google.visualization.datatable(); data.addcolumn('string', 'node'); data.addcolumn('string', 'parent'); data.addcolumn('string', 'nodeid'); data.addrows(json.parse(document.getelementbyid("<%=hiddenfield1.clientid%>").value)); // var chart = new google.visualization.orgchart(document.getelementbyid('chart_div')); function selecthandler() { var selecteditem = chart.getselection()[0]; if (selecteditem) { var oind = data.getvalue(selecteditem.row, 2); var arrloop = chart.getchildrenindexes(selecteditem.row); var arrconcat = chart.getchildrenindexes(selecteditem.row); (var = 0; < arrloop.length; i++) { var arr2 = new array(chart.getchildrenindexes(arrloop[i]).length); arr2 = chart.getchildrenindexes(arrloop[i]); (var j = 0; j < arr2.length; j++) { arrconcat.push(arr2[j]); } arrconcat.concat(arr2); } var arrchilds = new array(arrconcat.length); (var = 0; < arrconcat.length; i++) { arrchilds[i] = data.getvalue(arrconcat[i], 2); } drawtable(oind, arrchilds); } } google.visualization.events.addlistener(chart, 'select', selecthandler); chart.draw(data, { allowhtml: true }); //for (var = 0; < data.getnumberofrows() ; i++) { // chart.collapse(i, true); //} }
not sure mean last child in chart. , chart doesn't seem support zoom, may have code or libraries. regarding problem of getting children , subchildren of selected, need deal recursion:
google.visualization.events.addlistener(chart, 'select', function(){ var children=[] var selected=chart.getselection()[0].row; function getchilds(index){ // recursive function, adds children of index (row) var childs=chart.getchildrenindexes(index); // children indexes of current index for(var = 0; < childs.length;i++){ // each children children.push(data.getvalue(childs[i],0)) // add title getchilds(childs[i]) // , call function children index, children , on >> recursive } } getchilds(selected) // start recursive function selected index console.log(children) })
here example: http://jsfiddle.net/36gg3ro1/1/
Comments
Post a Comment