以下代码作为一个独立的页面本身运行良好。但是如果合并到我的 PHP Web 应用程序中,它会抛出错误。 google chart JS报错怎么调试? 任何建议都会有所帮助
<!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>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="myGraphLabel" onclick="drawColumnChart();">
My Column Chart
</div>
<div id="myColumnChart" style="width: 600px; height: 400px;"></div>
</body>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
function drawColumnChart() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', 'Hours per Day');
data.addRows(2);
data.setValue(0, 0, 'Work');
data.setValue(0, 1, 11);
data.setValue(1, 0, 'Eat');
data.setValue(1, 1, 2);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('myColumnChart')).
draw(data, {title:"So, how was your day?"});
}
</script>
</html>
Chrome 中的错误:它显示“无法读取未定义的属性‘长度’”,容器中的背景为红色
Firefox 中的错误: 在 Firebug 控制台中抛出错误: b[c] 未定义 http://www.google.com/uds/api/visualization/1.0/97e6275dc5c50efe5944ddda289e59d2/format+en,default,corechart.I.js 785行
最佳答案
如果您使用的是 Prototype JS 框架,则此答案将适用。 (我在这里没有看到它,但它可能已被排除)。
Google Visualization API 上有针对此问题的工单 here .
一个潜在的问题是原型(prototype)或其他库的版本可能存在冲突。
或者,reduce 函数可能需要重新定义:
<script type="text/javascript">
Array.prototype.reduce = undefined;
</script>
[注意:我过去遇到过这个问题,这导致了解决方案。我第二次遇到这个问题,但原来的解决方案不适用于这个新问题。您的里程可能会有所不同。]
关于javascript - 谷歌图表错误 :Cannot read property 'length' of undefined; Debugging error in Google Charts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7759231/