Google 可视化未显示在 Google 应用引擎上的 JSP 中

发布于 2025-01-04 23:50:01 字数 2055 浏览 4 评论 0原文

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

谢谢! 乔恩

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

So I want to use the visualization map from google and I want to display on my JSP generated page. t is being hosted on Google AppEngine. When I run the JSP on Google App Engine, this is the final output that is generated. However, after being compiled, the code looks good and when I put into google code playground, it works, but on the google app engine, it doesn't work at all! Here is the code that is sent to the webpage. I am at a complete loss as to how to fix this. Any help would greatly be appreciated.

Thanks!
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&v=2&sensor=true&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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2025-01-11 23:50:01

存在一些问题:

  • 保存主要 javascript 内容的
  • 对元素的引用应该是 document.getElementById('map_canvas')); 而不是 document.getElementById( 'container.page-wrap.mainContent.map_canvas'));
  • 我不确定您打算如何触发 drawVisualization,但请考虑一下: google.setOnLoadCallback(drawVisualization); 将在加载时调用该函数。

通过这些更改,代码将运行。希望有帮助!

There are a few issues:

  • The <script> block that holds your main javascript content includes the following attribute: language="text/javascript". This should be: type="text/javascript"
  • The reference to the element should be document.getElementById('map_canvas')); not document.getElementById('container.page-wrap.mainContent.map_canvas'));
  • I'm not sure how you're intending on triggering drawVisualization, but consider this: google.setOnLoadCallback(drawVisualization); which will call the function on load.

With those changes the code runs. Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文