duanmeng3476 2016-09-30 03:40
浏览 129

使用AJAX刷新Morris图表

As the first I would like to apologise for my bad English. Though I understand the English language, but can express myself In writing, unfortunately, very badly. So I use a translator's tool.

Now I come to my question:

With pleasure I would update my charts shown with Morris.js with a button. I already have several hours experimented. Till present here I show you once my code:

data_statistik.php

    <div id="data_statistik" class="col-md-12">

      <div class="box box-primary">
        <div class="box-header with-border">
          <h3 class="box-title">Icecast Statistik</h3>
          <button id="ReLoadData" type="button" class="btn btn-primary">Statistik refresh</button>
        </div>
        <!-- /.box-header -->
        <div class="box-body">

          <div class="row">

            <div class="col-md-12">

              <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
              <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
              <script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
              <script src="http://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>

              <div id="IcecastGraph"></div>

              <?php

              $sth = $pdo->prepare("SELECT * FROM statistik");
              $sth->execute();
              $result = $sth->fetchAll();

              ?>

              <script>

                var graph = Morris.Line({
                            element: 'IcecastGraph',
                            data: <?php echo json_encode($result); ?>,
                            xkey: 'listener_timestamp',
                            ykeys: ['listener_count'],
                            labels: ['Hörer']
                            });

                $(document).ready(function(){

                  $( "#ReLoadData" ).click(function() {

                    $.ajax({
                    url: "pages/management/data_statistik_content.php",
                    type: "POST",
                    dataType: "json",
                    success: function (data) {

                      var data = JSON.stringify(data);

                      graph.setData(data);

                    },

                    });

                  });

                });

              </script>

            </div>  
          </div>

        </div>
      </div>

    </div>

data_statistik_content.php

    <?php

    session_start();

    include("../../inc/config.inc.php");
    include("../../inc/functions.inc.php");

    $user = check_user();

    $sth = $pdo->prepare("SELECT * FROM statistik");
    $sth->execute();
    $result = $sth->fetchAll();

    header('Content-Type: application/json');

    echo json_encode($result);

    ?>

The Chart it is shown. The renew of the data doesn't work. Why?

I hope somebody here know my mistake?

Thank you very much

Greeting Björn

  • 写回答

3条回答 默认 最新

  • dongsha9208 2016-09-30 04:06
    关注

    Redraw the char using redraw()

    graph.setData(data);
    graph.redraw();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办