Php 无法使用mysqldata在组织google图表中添加用户及其图片的更多详细信息
我正在使用mysql数据创建一个组织谷歌图表。我能够从mysql数据库中检索数据并显示为层次结构,但问题是我无法显示存储在数据库中的图表中每个人的图像。子数据和父数据存储在一个数组中,im无法在图表中显示此人的更多详细信息。如果我添加一个从mysql数据库获得的额外数据,我的代码只取第一个值,只显示人名,我想在这里显示更多的人名细节 这是我的密码:Php 无法使用mysqldata在组织google图表中添加用户及其图片的更多详细信息,php,json,google-api,google-visualization,Php,Json,Google Api,Google Visualization,我正在使用mysql数据创建一个组织谷歌图表。我能够从mysql数据库中检索数据并显示为层次结构,但问题是我无法显示存储在数据库中的图表中每个人的图像。子数据和父数据存储在一个数组中,im无法在图表中显示此人的更多详细信息。如果我添加一个从mysql数据库获得的额外数据,我的代码只取第一个值,只显示人名,我想在这里显示更多的人名细节 这是我的密码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include_once('dbconfig.php');
$query = $connection->prepare('SELECT hierarchy.child,hierarchy.id,usertest.userID, usertest.name
FROM hierarchy
INNER JOIN usertest
ON hierarchy.userID=usertest.userID
ORDER BY hierarchy.id');
$query->execute();
$results = $query->get_result();
$flag = true;
$table = array();
$table['cols'] = array(
array('label' => 'child', 'type' => 'string','image'),
array('label' => 'Parent', 'type' => 'string'),
array('label' => 'userID', 'type' => 'number', 'role' => 'tooltip','trigger'=>'selection' ),
);
$table['rows'] = array();
foreach ($results as $row) {
$temp = array();
$temp[] = array('v' => $row['child']);
$temp[] = array('v' => $row['name']);
$temp[] = array('v' => $row['userID']);
$table['rows'][] = array('c' => $temp);
}
$jsonTable = json_encode($table);
?>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable(<?php echo $jsonTable; ?>);
// Create and draw the visualization.
var table = new google.visualization.OrgChart(document.getElementById('visualization'));
table.draw(data, {legend:'none', width:10000, height:400,border: '#000000'});
}
google.setOnLoadCallback(drawVisualization);
google.load('visualization', '1', {packages: ['orgchart']});
google.visualization.events.addListener(table,'select', function() {
alert('selected');
});
// Add our over/out handlers.
</script>
</head>
<body style="font-family: Arial;border: ;#000000">
<div id="visualization" style="width: 500px; height: 300px; background: #000000;"></div>
</body>
</html>
谷歌可视化API示例
函数drawVisualization(){
//创建并填充数据表。
var data=new google.visualization.DataTable();
//创建并绘制可视化。
var table=new google.visualization.OrgChart(document.getElementById('visualization');
表.绘图(数据,{图例:'none',宽度:10000,高度:400,边框:'#000000'});
}
setOnLoadCallback(drawVisualization);
load('visualization','1',{packages:['orgchart']});
google.visualization.events.addListener(表,'select',function(){
警报(“选定”);
});
//添加我们的over/out处理程序。
提前感谢在上的示例中,前两个节点的第一个元素是带有字段“v”和“f”的数组v'是节点的id值f'是该节点中显示的内容。如果您只需将所有要显示的信息添加到与“f”相关联的字段中,您应该能够显示所有想要显示的信息
您应该将细节与您喜欢的任何标记连接在一起。例如:
$temp[] = array('v' => $row['name'], 'f' => "<h3>{$row['id'] }</h3><p>{$row['picture'']}</p>");
问题是我无法在图表中添加更多显示更多员工的详细信息,因为根据谷歌组织图表的要求,在我提到的columns字段中。数组中的第二个字段始终被视为父字段。因此,我无法显示更多详细信息。在链接的API文档页面上的示例中,前两个节点的第一个元素是一个包含字段“v”和“f”的数组v'是节点的id值f'是该节点中显示的内容。如果您只需将所有要显示的信息添加到与“f”关联的字段中,您应该能够显示所有您想显示的信息。您好,非常感谢您及其工作,您能告诉我如何显示一个人的多行或多个详细信息吗。我试图这样写,但它只显示第一个值$temp[]=数组('v'=>$row['name'],'f'=>$row['id'],$row['picture']);您应该将细节与您喜欢的任何标记连接在一起。例如:$temp[]=array('v'=>$row['name'],'f'=>“{$row['id']}{$row['picture']}”;谢谢somuch nickRise,请在回答部分张贴你的答案,这样我可以标记它
chart.draw(data, {allowHtml:true});