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

发布于 2024-12-09 20:29:48 字数 1969 浏览 0 评论 0原文

以下代码本身作为独立页面可以正常工作。但如果合并到我的 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路

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铃予 2024-12-16 20:29:48

如果您使用 Prototype JS 框架,这个答案将适用。 (我在这里没有看到它,但它可能已被排除)。

此处。

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

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

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

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

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.]

药祭#氼 2024-12-16 20:29:48

在我的网络应用程序中,我包含了“prototype-1.6.0.2.js”,这导致了此错误!
如果我排除“prototype-1.6.0.2.js”,一切都运行良好!

In my web app, I had included 'prototype-1.6.0.2.js', which created this error !
If I exclude 'prototype-1.6.0.2.js', everything runs great !

悸初 2024-12-16 20:29:48

我遇到了类似的问题,谷歌图表工具和原型库发生冲突。我将 Prototype 从版本 1.6.1 升级到 1.7.1,问题就消失了。

I had a similar issue where Google chart tools and Prototype library conflicted. I upgraded Prototype from version 1.6.1 to 1.7.1 and the problem was gone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文