Uncaught Error: Container Is Not Defined - Google Pie Charts
Uncaught Error: Container Is Not Defined - Google Pie Charts
这是我正在尝试做的事情。
我正在尝试根据以下代码在 PHP 循环中加载一堆 Google 饼图:
<?php
foreach ($currentTeamLeaders as $key=> $currentTeamLeader) {
$chartId = 'chart-'.$key;
?>
<script>
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
chartArea:{right:0,top:0,width:"90%",height:"100%" },
height: 150,
width: 250,
};
var chart = new google.visualization.PieChart(document.getElementById(<?php echo $chartId ?>));
chart.draw(data, options);
}
</script>
<div id="<?php echo $chartId ?>" style="width: 300px; height: 300px;"></div>
<?php
}
?>
但出于某种原因,我收到未捕获的错误:尽管定义了 div,但容器未定义。
谢谢
已解决:
我需要在 PHP echo 语句后面添加引号。
这是我正在尝试做的事情。
我正在尝试根据以下代码在 PHP 循环中加载一堆 Google 饼图:
<?php
foreach ($currentTeamLeaders as $key=> $currentTeamLeader) {
$chartId = 'chart-'.$key;
?>
<script>
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
chartArea:{right:0,top:0,width:"90%",height:"100%" },
height: 150,
width: 250,
};
var chart = new google.visualization.PieChart(document.getElementById(<?php echo $chartId ?>));
chart.draw(data, options);
}
</script>
<div id="<?php echo $chartId ?>" style="width: 300px; height: 300px;"></div>
<?php
}
?>
但出于某种原因,我收到未捕获的错误:尽管定义了 div,但容器未定义。
谢谢
已解决:
我需要在 PHP echo 语句后面添加引号。