【发布时间】:2012-09-26 08:07:23
【问题描述】:
我正在使用 Ajax 代码加载 html 页面
例如:
$.ajax({
url: 'Context.html',
dataType: 'html',
timeout: 500,
success: function(html) {
$("div#mainbody").html(html);
}
});
Context.html 我正在将它加载到其他一些 html 页面中,比如 Home.html
但我在 Context.html 中使用谷歌 API 生成饼图
生成饼图的代码,即在 Context.html 中是
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Count'],
['2005', 70],
['2006', 80],
['2007', 140],
['2008', 220],
['2009', 290],
['2010', 400],
['2011', 500]
]);
var options = {
title: 'Head Count-(Apple Year)',
colors:['#129212']
};
var chart = new google.visualization.ColumnChart(document.getElementById('jsf_headcount_bargraph'));
chart.draw(data, options);
}
</script>
当我在 Home.html 页面中加载 Context.html 时,在 Home.html 中加载 Context.html 后找不到饼图
我尝试给 ALERT("");在我为饼图编写代码的脚本中。我收到警报消息,所以 Ajax 正在执行 javascript,但我没有得到相同脚本的饼图。所以我被困在 Home.html 页面中加载饼图
【问题讨论】:
-
替代方案:在同一页面上绘制图表并保持隐藏直到不需要。或者您可以使用图像饼图。希望这会奏效。
-
我也有同样的问题,怎么办?
-
Context.html 的唯一目的是绘制图表,还是还有其他用途? div "jsf_headcount_bargraph" 是在您的主页中还是在 context.html 中?
标签: html ajax google-visualization