Highcharts,加载然后刷新

时间:2017-09-06 10:32:48

标签: jquery ajax highcharts settimeout intervals

我有一个用ajax运行的高级图表,

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

除了,我需要图表加载striaght然后每隔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
    });
}

1 个答案:

答案 0 :(得分:0)

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

    let initialViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarVC") as! UITabBarController
    appDelegate.window?.rootViewController = initialViewController
    appDelegate.window?.makeKeyAndVisible()
    initialViewController.selectedIndex = 2