2017-08-24 291 views
1

我創建了一個圖表,我想實時更新,這就是爲什麼我使用ajax。我的問題是,如何顯示ajax響應?以下是我的圖表示例腳本。請幫幫我。非常感謝。如何顯示ajax響應

Chart.php -

$(document).ready(function() { 
    Highcharts.chart('container', { 
     chart: { 
      type: 'bar' 
     }, 
     title: { 
      text: "TITLE" 
     }, 
     series: [{ 
      name: 'Present', 
      data: [*//must display the ajax response here//*] 
     }] 
    }); 
}); 

ajax.php

<script> 
function fanc_no(){ 
    $.ajax({ 
     url: "test.php", 
     success: function(result){ 
      $("#container").html(result); 
     } 
    }); 
} 
window.setInterval(function(){ 
    func_no(); 
}, 1000); 
</script> 
+1

[使用Ajax將數據加載到Highcharts中]可能的副本(https://stackoverflow.com/questions/12223972/load-data-into-highcharts-with-ajax) –

回答

0

看看在load功能:現在

chart: { 
    events: { 
     load: function() { 

      // set up the updating of the chart each second 
      var series = this.series[0]; 
      setInterval(function() { 
       var x = (new Date()).getTime(), // current time 
        y = Math.round(Math.random() * 100); 
       series.addPoint([x, y], true, true); 
      }, 1000); 
     } 
    } 
} 

,該setInterval函數內部,你必須調用你的ajax並傳遞結果如圖所示。

看看它the official docs

+0

Hello!有沒有其他的條形圖選項?這顯示爲線圖。 – COCECS

+0

我想這適用於線條和條形圖。如果不嘗試下面的答案。 – treolandix

+0

這不起作用。它總是說,這個網頁正在放緩網站。 – COCECS