我总是收到此错误" Uncaught SyntaxError:意外的令牌"。但我无法在我的代码中找到所述错误。我已经检查了括号,没有任何问题。请帮我弄清楚错误是什么。谢谢!
这里是代码(此代码由xslt自动转换):
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://www.google.com/jsapi"></script><script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
</script>
</head>
<body># Of Issues (all) Per HelpDesk Agent Per Day<div id="chartdiv_1"></div><script type="text/javascript">
google.setOnLoadCallback(drawChart_1);
function drawChart_1() {
var isProportional=1;
var chart = new google.visualization.ColumnChart(document.getElementById('chartdiv_1'));
var options = {width:1000, height:400, isStacked: true};
var data = google.visualization.arrayToDataTable([
['Date','User1','User2','User3']
,['01/21/2014',5,0,0]
,['01/22/2014',0,13,0]
,['01/23/2014',0,4,0]
,['01/24/2014',7,0,0]
,['01/25/2014',0,0,0]
]);
if (isProportional==1) {
var view = new google.visualization.DataView(data);
var columns=[0];
for (var i=1; i < data.getNumberOfColumns(); i++) {
columns.push({
type: 'number',
label: data.getColumnLabel(i),
calc: (function (col) {
return function (dt, row) {
var val = dt.getValue(row, col);
var total = 0;
for (var j = 1; j < dt.getNumberOfColumns(); j++) {
total += dt.getValue(row, j);
}
return (total == 0) ? null : {v: val / total, f: val.toString()};
};
})(i)
});
columns.push({
type: 'string',
role: 'annotation',
sourceColumn: i,
calc: 'stringify'
});
view.setColumns(columns);
chart.draw(view, options);
} else {
chart.draw(data, options);
}
}
</script></body>
</html>
答案 0 :(得分:3)
第25行,for (var i=1; i < data.getNumberOfColumns(); i++) {
应为for (var i=1; i < data.getNumberOfColumns(); i++) {
(请注意&lt;)
答案 1 :(得分:1)
我使用JSHint对您的代码进行了操作,并且您没有先关闭for
语句。如果你真的需要在script
标签内编写代码,我真的建议在外部文件中使用Lint工具编写它,然后复制并粘贴它,这样可以防止这样的错误。