2009-09-29 55 views
0

早上好!Google可視化運動圖未定義?

今天早上我遇到了一個問題,我向應用程序添加了Google Visualization Motion Chart。但像大多數情況下,它不符合瀏覽器標準。在FF3中,它工作正常,但在Safari和IE 7中,錯誤控制檯顯示:「TypeError:表達式結果'google.visualization'[undefined]不是一個對象。」

我不知道它爲什麼會發生,或者我可以在我的代碼中進行更改。這是我使用的代碼片段。感謝您的幫助!

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

回答

2

我有同樣的問題。我發現我必須在頭元素中包含jsapi腳本和可視化包,如果它包含在主體中,它不起作用:

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