【问题标题】:Google Visualization Motion Chart Undefined?谷歌可视化动态图表未定义?
【发布时间】:2009-09-29 15:03:17
【问题描述】:

大家早上好!

今天早上我遇到了一个问题,我在我的应用程序中添加了一个 Google 可视化动态图表。但像大多数事情一样,它不兼容跨浏览器。在 FF3 中它可以正常工作,但在 Safari 和 IE 7 中,错误控制台显示:“TypeError: Result of expression 'google.visualization' [undefined] is not an object。”

我不确定它为什么会发生,或者我可以在我的代码中更改什么。这是我正在使用的代码的 sn-p。感谢您的帮助!

<div id="NRG-motion-chart" style="width: 625; height: 625px;"></div>

        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">

    google.load('visualization', '1', {'packages':['motionchart']});
    google.setOnLoadCallback(drawChart);
    function drawChart() {
        var nrgChart = new google.visualization.DataTable();
        nrgChart.addColumn('string', 'Business Unit');
        nrgChart.addColumn('date', 'Date');
        nrgChart.addColumn('number', 'Sales');
        nrgChart.addColumn('number', 'Covers');
        nrgChart.addColumn('number', 'Sales Per Man Hour');
        nrgChart.addColumn('number', 'Labor Hours Per Cover');
        nrgChart.addColumn('string', 'Location');
        nrgChart.addRows([<?= $gData['gData']; ?> ]);
        var chart = new google.visualization.MotionChart(document.getElementById('NRG-motion-chart'));
        chart.draw(nrgChart, {width: 625, height:625});
    }
    </script>

【问题讨论】:

    标签: javascript google-visualization


    【解决方案1】:

    我遇到了同样的问题。我发现我必须在head元素中包含jsapi脚本和可视化包,如果它包含在body中它不起作用:

    <html>
      <head>
        <script src="http://www.google.com/jsapi" type="text/javascript"></script>
        <script type="text/javascript">
          google.load("visualization", "1", {packages:["motionchart"]});
          google.setOnLoadCallback(function() {
            //google.visualization will be defined here
          }); 
        </script>
      </head>
      <body>
        <!-- Everything else... -->
      </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多