dongshiliao7990 2018-07-20 12:08
浏览 126
已采纳

重新加载然后刷新相同的函数jquery

In my PHP application I'm using 2 php files.

  1. chart.php - Page contains a google chart.

    <div id="chart_div" style="height:100%;width:100%">
    </div>
    
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawStuff);
    
      function drawStuff() {
        var data = new google.visualization.arrayToDataTable([
          ['Opening Move', 'Percentage'],
          ["King's pawn (e4)", 44],
          ["Queen's pawn (d4)", 31],
          ["Knight to King 3 (Nf3)", 12],
          ["Queen's bishop pawn (c4)", 10],
          ['Other', 3]
        ]);
    
        var options = {
          title: 'Chess opening moves',
          width: 900,
          legend: { position: 'none' },
          chart: { title: 'Chess opening moves',
                   subtitle: 'popularity by percentage' },
          bars: 'horizontal', // Required for Material Bar Charts.
          axes: {
            x: {
              0: { side: 'top', label: 'Percentage'} // Top x-axis.
            }
          },
          bar: { groupWidth: "90%" }
        };
    
        var chart = new google.charts.Bar(document.getElementById('chart_div'));
        chart.draw(data, options);
            google.visualization.events.addListener(chart, 'select', selectHandler);
      };
    
      function selectHandler() {
         window.location.href = "chart.php";
      }
    </script>
    

2. index.php - Home page where I'm including chart.php in a div

<div style="width:40%">
require_once 'chart.php';
</div>

On clicking the chart in index.php page , it will call selectHandler() and redirect to chart.php.

The issue is, the chart in chart.php (after redirecting from index.php) is showing in small size similar to the chart display in index.php. Once I refreshes the chart.php it will display the chart in correct size.

Is there any function in jquery to refresh a page by reloading other than using location.reload().

Can anyone help me to fix this issue? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongshen9058 2018-07-20 13:07
    关注

    try redrawing the chart,
    use an inline function on your select handler,
    so you can still access your chart, data, and options.

    google.visualization.events.addListener(chart, 'select', function () {
      window.location.href = "chart.php";
      chart.draw(data, options);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)