谷歌图表错误:无法读取未定义的属性"长度"; Google图表中的调试错误

met*_*awk 3 javascript google-visualization

以下代码作为独立页面可以正常工作.但如果将其合并到我的PHP Web应用程序中,则会引发错误.如果在谷歌图表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>
Run Code Online (Sandbox Code Playgroud)

Chrome中出现错误:显示"无法读取未定义的属性'长度",容器中有红色背景

Firefox中的错误:在Firebug控制台中引发错误:b [c]未定义 http://www.google.com/uds/api/visualization/1.0/97e6275dc5c50efe5944ddda289e59d2/format+en,default,corechart.I.js 第785行

VOI*_*and 9

如果您使用的是Prototype JS框架,那么这个答案将适用.(我在这里看不到,但它可能被排除在外).

此处的Google Visualization API上有针对此问题的故障单.

一个潜在的问题是可能存在冲突版本的原型或包含的其他库.

或者,可能需要重新定义reduce函数:

<script type="text/javascript">
  Array.prototype.reduce = undefined;
</script>
Run Code Online (Sandbox Code Playgroud)

[注意:过去我遇到过这个问题,这导致了解决方案.我第二次遇到这个问题,但原始解决方案不适用于这个新问题.你的旅费可能会改变.]