Google图表错误:无法读取未定义的属性“长度”;在Google Charts中调试错误 [英] Google charts error:Cannot read property 'length' of undefined; Debugging error in Google Charts

查看:77
本文介绍了Google图表错误:无法读取未定义的属性“长度”;在Google Charts中调试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码可以作为独立页面正常工作。但是,如果纳入我的PHP Web应用程序,它会引发错误。如何调试如果错误发生在谷歌图表JS?
任何建议都会有所帮助

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8/>
< title>
Google Visualization API示例
< / title>
< / head>

< body style =font-family:Arial; border:0 none;>
< div id =myGraphLabelonclick =drawColumnChart();>
我的柱形图
< / div>
< div id =myColumnChartstyle =width:600px; height:400px;>< / div>
< / body>

< script type =text / javascriptsrc =http://www.google.com/jsapi>< / script>

< script type =text / javascript>
google.load('visualization','1',{packages:['corechart']});

函数drawColumnChart(){
//创建并填充数据表。
var data = new google.visualization.DataTable();
data.addColumn('string','Task');
data.addColumn('数字','每日小时数');
data.addRows(2);
data.setValue(0,0,'Work');
data.setValue(0,1,11);
data.setValue(1,0,'吃');
data.setValue(1,1,2);

//创建并绘制可视化文件。
new google.visualization.PieChart(document.getElementById('myColumnChart'))。
draw(data,{title:那么,今天过得如何?});
}
< / script>
< / html>

Chrome出现错误:显示Can not read property'length'of undefined,在容器中有红色背景



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

一个潜在的问题是可能存在相互冲突的原型版本或其他库。



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

  < script type =text / javascript> 
Array.prototype.reduce = undefined;
< / script>

[注意:过去我遇到过这个问题,这导致了解决方案。我第二次遇到此问题,但原始解决方案不适用于此新问题。你的里程可能会有所不同。]


The following code works fine as a independant page as itself. But if incorporated into my PHP web app, it throws error. How to debug if the error happens in the google chart JS? Any suggestions will be helpful

<!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>

Error in Chrome: It displays "Cannot read property 'length' of undefined", With a red background in the container

Error in Firefox: Throws error in Firebug console as: b[c] is undefined http://www.google.com/uds/api/visualization/1.0/97e6275dc5c50efe5944ddda289e59d2/format+en,default,corechart.I.js Line 785

解决方案

This answer will apply if you are using the Prototype JS framework. (I don't see it here, but it might have been excluded).

There is a ticket open for this issue on the Google Visualization API here.

One potential issue is that there might be a conflicting version of prototype or some other library being included.

Alternately, the reduce function may need to be redefined:

<script type="text/javascript">
  Array.prototype.reduce = undefined;
</script>

[Note: I had this issue in the past, and this led to the solution. I am experiencing this issue a second time, but the original solution is not working for this new issue. Your mileage may vary.]

这篇关于Google图表错误:无法读取未定义的属性“长度”;在Google Charts中调试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆