I've setup a Google charts (org chart) implementation that accepts the list of rows as a variable, ultimately coming from PHP. If I try to render the org chart using that variable, I get the error "every row given must be either null or an array." If I alert(userlist)
prior to the addRows
command, copy that output, and replace the variable with the output, all is well, so I know that it's receiving the data properly. Here's what I've got so far:
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');
// Pull user information from Drupal
var userlist = Drupal.settings.orgchart.userlist;
// For each orgchart box, provide the name, manager, and tooltip to show.
alert(userlist);
data.addRows([userlist]);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('org-chart'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
}
Again, if I replace userlist in data.addRows([userlist]);
with the output from alert(userlist)
it works great.
UPDATE: here is the raw output:
[{v:'CN=My Name,OU=IT,OU=Fesslers,DC=hpsi,DC=local', f:'My Name'}, 'CN=Supervisor Name,OU=Sr. Management,OU=Fesslers,DC=hpsi,DC=local', ''], [{v:'', f:'Another Name'}, '', ''], [{v:'CN=Yet Another,OU=IT,OU=Fesslers,DC=hpsi,DC=local', f:'Yet Another'}, 'CN=My Name,OU=IT,OU=Fesslers,DC=hpsi,DC=local', '']
UPDATE: adding in the PHP that creates my userlist variable:
$allusers = entity_load('user');
$userlist = '';
if ($allusers) {
foreach ($allusers as $useritem) {
$dn = '';
$manager = '';
$fullname = '';
if ($useritem->uid > 1) { // Skip user 0 and 1
if (isset($useritem->field_distinguished_name['und']['0']['value'])) {
$dn = $useritem->field_distinguished_name['und']['0']['value'];
}
if (isset($useritem->field_manager_dn['und']['0']['value'])) {
$manager = $useritem->field_manager_dn['und']['0']['value'];
}
if (isset($useritem->field_full_name['und']['0']['value'])) {
$fullname = $useritem->field_full_name['und']['0']['value'];
}
($userlist == '') ? $userlist = '[[{v:\'' . $dn . '\', f:\'' . $fullname . '\'}, \'' . $manager . '\', \'\']' : $userlist .= ', [{v:\'' . $dn . '\', f:\'' . $fullname . '\'}, \'' . $manager . '\', \'\']';
}
}
if ($userlist != '') {
$userlist .= ']';
}
}