0
votes

Good Morning all!

I'm running into an issue this morning where I added a Google Visualization Motion Chart to my application. But like most things its not cross browser compliant. In FF3 it works fine but in Safari and IE 7 the error console says: "TypeError: Result of expression 'google.visualization' [undefined] is not an object."

I'm not sure why it is happening or what I can change in my code. Here is the snippet of code that I'am using. Thank you for the help!

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

1 Answers

2
votes

I had the same problem. I found that I had to include the jsapi script and visualization packages in the head element, it didn't work if it was included in the 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>