I'm building an organizational hierarchy chart using Google charts API.
I'm able to render a structured tree-like chart by pulling in some data from my database, but I also want to display some metadata when a user hovers over a particular row.
For instance, when a user hovers over an employees name, I want to display like the city the employee is currently employed in.
Console output after making adjustments
How could I go about this? Here is the code I have so far:
$table = array();
$table['cols'] = array(
array('label' => 'Name', 'type' => 'string'),
array('label' => 'Manager', 'type' => 'string'),
//array('role' => 'ToolTip', 'type' => 'string'),
);
$table['rows'] = array();
foreach ($employeeStruct as $row) {
$temp = array();
$temp[] = array('v' => $row['first_name']);
$temp[] = array('v' => $row['managers_first_name']);
$temp[] = array('v' => $row['work_city']);
$table['rows'][] = array('c' => $temp);
}
$jsonTable = json_encode($table);
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-
fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Structured Organization</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js">
</script>
<script type="text/javascript">
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(<?php echo $jsonTable;
?>);
data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html':
true}});
var options = {
tooltip: {isHtml: true},
legend: 'none',
allowHtml: true,
allowCollapse: true,
};
// Create and draw the visualization.
var chart = new
google.visualization.OrgChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>