Google线形图不会在我重新加载div时重新加载 [英] Google line chart not reloading when I reload the div

查看:78
本文介绍了Google线形图不会在我重新加载div时重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到Google线图API问题。当我重新加载div时,折线图不会再次加载。

I am having issue with Google line chart API. When I reload the div, the line chart does not load again.

这是折线图的代码

<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的代码

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>


推荐答案

所以这可能是问题。

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);

即使您正在重新加载此内容,页面仍然有这些引用加载了
,因为
的谷歌脚本没有加载任何新的内容

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

来解决这个问题,你可能想要第二次调用drawChart在加载新内容后自己调用drawChart函数

to get around this you might want to call the drawChart function yourself after having loaded the new content

success: function(msg){
   drawChart();
 }

也许这会有所帮助。 gl

maybe this will help. gl

这篇关于Google线形图不会在我重新加载div时重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆