当我重新加载 div 时,Google 折线图不会重新加载
我在使用 Google 折线图 API 时遇到问题。当我重新加载 div 时,折线图不会再次加载。
这是折线图的代码
<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 = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addRows(4);
<?php
//gets line chart data
echo $join;?>
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 320, height: 250, title: ''});
}
</script>
<h3>Sales History</h3>
<table border="5" style="border-color: #3b6aa8;" >
<tr>
<td>
<div id="chart_div" style="border: 1;border-color: green;"></div>
</td>
</tr>
</table>
用于重新加载 div 的代码
<script type="text/javascript">
$(document).ready(function() {
$('#sliderform').submit(function() {
bodyContent = $.ajax({
url: "dashboardreload.php",
global: false,
type: "POST",
data: ({year : $("#yearval").val(), month: $("#monthval").val(),day : $("#dayval").val(),
year1 : $("#year1val").val(), month1: $("#month1val").val(),day1 : $("#day1val").val()
}),
dataType: "html",
async:false,
success: function(msg){
//alert('test');
}
}
).responseText;
$('#dash').html(bodyContent);
//confirm(bodyContent);
return false;
});
});
</script>
I am having issue with Google line chart API. When I reload the div, the line chart does not load again.
This is the code for line chart
<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 = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addRows(4);
<?php
//gets line chart data
echo $join;?>
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 320, height: 250, title: ''});
}
</script>
<h3>Sales History</h3>
<table border="5" style="border-color: #3b6aa8;" >
<tr>
<td>
<div id="chart_div" style="border: 1;border-color: green;"></div>
</td>
</tr>
</table>
code used to reload the div
<script type="text/javascript">
$(document).ready(function() {
$('#sliderform').submit(function() {
bodyContent = $.ajax({
url: "dashboardreload.php",
global: false,
type: "POST",
data: ({year : $("#yearval").val(), month: $("#monthval").val(),day : $("#dayval").val(),
year1 : $("#year1val").val(), month1: $("#month1val").val(),day1 : $("#day1val").val()
}),
dataType: "html",
async:false,
success: function(msg){
//alert('test');
}
}
).responseText;
$('#dash').html(bodyContent);
//confirm(bodyContent);
return false;
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我假设代码
正在尝试将 div 重新插入页面
并且您正在从服务器获取新版本,
#dash 元素在您的代码中不可见,但我是
假设它是父标签。
这段代码试图
首先在 javascript 中重新获取页面,您定义一个这样的变量,
否则您将遇到一些麻烦,否则在全局范围内
,其次 ajax 调用是异步的,您拥有的成功方法是什么
在 rdy 时为您提供服务器的响应
我希望这有帮助
so im going to asume that the code
is trying to reinsert the div into the page
and you are fetching a new version from the server
the #dash element is not visible in your code here but i am
assuming its a parent tag.
and this code is trying to refetch the page
first of all in javascript you define a variable like this
you will run in to some truble otherwise with global scope
and secondly ajax calls are async the success method you have there is what
gives you the response from the server when its rdy
i hope this helps
所以这可能是问题所在,
即使您正在重新加载此内容,页面仍然加载了这些引用
并且第二次可能不会调用drawChart,因为
谷歌脚本没有加载任何新内容
来解决这个问题,您可能想在加载新内容后自己调用drawChart函数,
也许这会有所帮助。格
so this might be the problem
even tho you are reloading this content the page still has these references loaded
and there might not ever be a call to drawChart on the second time around because
the google script isn't loading any new content
to get around this you might want to call the drawChart function yourself after having loaded the new content
maybe this will help. gl