yingyang
yingyang

Reputation: 47

Uncaught SyntaxError: Unexpected token else

I always get this error "Uncaught SyntaxError: Unexpected token else ". But I can't find the said error in my code. I already check the brackets and its nothing wring. Help me to find out what's the error, please. Thanks!

Here's the code (This code automatically transformed by 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 &lt; 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 &lt; 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>

Upvotes: 0

Views: 5574

Answers (2)

dpsxp
dpsxp

Reputation: 11

I Linted your code, with JSHint and you're not closing you first for statement. If you really need to write the code inside the script tag, I really recommend to write it using a Lint tool in a external file then copy and paste it, it will prevent errors like this.

Upvotes: 1

NoGray
NoGray

Reputation: 1149

line 25, for (var i=1; i &lt; data.getNumberOfColumns(); i++) { should be for (var i=1; i < data.getNumberOfColumns(); i++) { (notice the <)

Upvotes: 3

Related Questions