谷歌可视化没有显示在谷歌应用程序引擎的JSP中

Google Visualization not showing in JSP on google app engine

本文关键字:谷歌 引擎 JSP 应用程序 可视化 显示      更新时间:2023-09-26

所以我想使用谷歌的可视化地图,并且我想在JSP生成的页面上显示。t正在Google AppEngine上托管。当我在GoogleAppEngine上运行JSP时,这是生成的最终输出。然而,编译后,代码看起来不错,当我把它放进谷歌代码游乐场时,它可以工作,但在谷歌应用程序引擎上,它根本不工作!这是发送到网页的代码。我完全不知道如何解决这个问题。如有任何帮助,我们将不胜感激。

谢谢!Jon

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>People</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=GOOGLEAPIKEYTHATISVALID" type="text/javascript"></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script language="text/javascript">
google.load('visualization', '1', {packages: ['geomap']});
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addRows(4);
data.addColumn('string', 'State');
data.addColumn('number', 'Popularity');
data.setValue(0, 0, 'Pennsylvania');
data.setValue(0, 1, 10);
data.setValue(1, 0, 'New York');
data.setValue(1, 1, 15);
data.setValue(2, 0, 'California');
data.setValue(2, 1, 5);
data.setValue(3, 0, 'New Jersey');
data.setValue(3, 1, 8);

var options = {};
options['region'] = 'US';
var geomap = new google.visualization.GeoMap(
document.getElementById('container.page-wrap.mainContent.map_canvas'));
geomap.draw(data, options);
}
</script>
</head>
<body > ##I have also done <body onload="drawVisualization()"> and that doesn't work either!
<div id="container">
<div id="headerBar">
<P> this is a pretty header </p>
</div>
<div id="page-wrap">
<div id="mainContent">
<div id="map_canvas"></div>                 
</div>
</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<div id="footer">
<P> This is the footer</P>
<!-- end #footer -->
</div>
<!-- end #container -->
</div>
</body>
</html>

有几个问题:

  • 包含主javascript内容的<script>块包括以下属性:language="text/javascript"。这应该是:type="text/javascript"
  • 对元素的引用应该是document.getElementById('map_canvas'));而不是document.getElementById('container.page-wrap.mainContent.map_canvas'));
  • 我不确定您打算如何触发drawVisualization,但请考虑一下:google.setOnLoadCallback(drawVisualization);,它将在加载时调用函数

有了这些更改,代码就会运行。希望能有所帮助!