早上好!
今天早上我遇到了一个问题,我在我的应用程序中添加了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>
答案 0 :(得分:2)
我遇到了同样的问题。我发现我必须在head元素中包含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>