这段代码旨在显示图表,但不会:
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
data.addcColumn('string', 'Type');
data.addColumn('number', 'Job Registration');
data.addRows([
<?php foreach ($chart_result as $result) {
echo $result;
}?>
]);
var options = {
title: 'Job Registration by Type',
hAxis: {title: '', titleTextStyle: {color: 'red'}}
};
var chart = new google.visualization.ColumnChart(document.getElementById('visualization'));
chart.draw(data, options);
}
当我提交表单并查看页面源时,这是 data.addRows 的结果:
data.addRows([
[' Engineer',1],['Assistant',1],['Developer',4],[' Ninja!',1],['Web Application Developer',1],
]);
这对我来说是正确的,但这是我第一次使用谷歌分析(或 JavaScript ......)并且我非常密切地关注现有图表的示例,所以它可能根本不正确。任何想法为什么这可能不起作用?
干杯