我正在尝试使用 Google 组织图表控件。我希望它可以单击展开/折叠节点(而不是默认的双击),并提供指向用户个人资料页面的超链接。
我的超链接代码适用于默认的双击展开/折叠。但是,如果我为“选择”事件添加一个侦听器以启用单击展开/折叠,则超链接将停止工作。
JSFiddle 这里https://jsfiddle.net/oxzabtyg/
这是我的代码
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', 'Manager');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows([
[{v:'Mike', f:'Mike<div><a href="http://www.google.com">google</a></div>'},'', 'The President'],
[{v:'Jim', f:'Jim<div><a href="http://www.google.com">google</a></div>'},'Mike', 'VP'],
['Alice', 'Mike', ''],
['Bob', 'Alice', ''],
[{v:'John', f:'John<div><a href="http://www.google.com">google</a></div>'},'Bob', 'VP'],
['Carol', 'Bob', ''],
[{v:'Jake', f:'Jake<div><a href="http://www.google.com">google</a></div>'},'John', 'VP']
]);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// selection
google.visualization.events.addListener(chart, 'select', function () {
// get the row of the node clicked
var selection = chart.getSelection();
var row = selection[0].row;
// get a list of all collapsed nodes
var collapsed = chart.getCollapsedNodes();
// if the node is collapsed, we want to expand it
// if it is not collapsed, we want to collapse it
var collapse = (collapsed.indexOf(row) == -1);
chart.collapse(row, collapse);
// clear the selection so the next click will work properly
chart.setSelection();
});
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true, allowCollapse:true});
}