from.. 2017-09-06 10:32 采纳率: 100%
浏览 53

高图,加载然后刷新

I have a highcharts chart running with ajax,

it gets the data and refreshes every 15 seconds which is perfectly fine

except, i need the chart to load striaght away and then refresh every 15seconds,

at the moment it waits 15 seconds before displaying on page load.

code below

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
    });
}
  • 写回答

1条回答 默认 最新

  • ~Onlooker 2017-09-06 10:36
    关注

    call your function when page loads. insert this after your code:

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

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作