【问题标题】:Highcharts, load then refreshHighcharts,加载然后刷新
【发布时间】:2017-09-06 10:32:48
【问题描述】:

我有一个使用 ajax 运行的 highcharts 图表,

它获取数据并每 15 秒刷新一次,这非常好

除了,我需要图表直接加载,然后每 15 秒刷新一次,

在页面加载前等待 15 秒。

代码如下

function getLiveData() {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $.ajax({
        url: '/get-converted-data',
        success: function(point) {
            var x = (new Date()).getTime();
            console.log(point);
            var series = liveChart.series[0];
            var series1 = liveChart.series[1];
            var series2 = liveChart.series[2];
            var series3 = liveChart.series[3];
                shift = series.data.length > 20; 
                shift1 = series1.data.length > 20; 
                shift2 = series2.data.length > 20; 
                shift3 = series3.data.length > 20; 

            // add the points
            liveChart.series[0].addPoint([x, point[0]], true, shift);
            liveChart.series[1].addPoint([x, point[1]], true, shift1);
            liveChart.series[2].addPoint([x, point[2]], true, shift2);
            liveChart.series[3].addPoint([x, point[3]], true, shift3);

            // call it again after 15 seconds,
            //this is loading the actual chart every 15 seconds,
            //i need the chart to load instantly then refresh every 15 seconds, any ideas?
            setTimeout(getLiveData, 15000);    
        }, 
        cache: false
    });
}

【问题讨论】:

  • 您只需要在页面加载后立即致电getLiveData()
  • 哇,谢谢,不敢相信我错过了

标签: jquery ajax highcharts settimeout intervals


【解决方案1】:

在页面加载时调用您的函数。在您的代码后插入:

$(function() {
    getLiveData();
});

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2016-10-28
    • 2010-11-21
    • 2018-02-04
    • 1970-01-01
    • 2015-07-31
    • 2013-09-12
    • 1970-01-01
    • 2012-05-18
    相关资源
    最近更新 更多