Highcharts - 加载并刷新csv [英] Highcharts - load and refresh csv

查看:279
本文介绍了Highcharts - 加载并刷新csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张图表(使用Highcharts)在一页上显示不同的数据。
要显示的数据来自CSV文件。
我的代码到目前为止工作,图表显示可视化的CVS内容。
但是:我需要每5分钟重新加载CSV,导致每5分钟将这些CSV文件写入新数据。
如何以最佳方式执行重新加载?
我的代码生成2个图表:

  $。get('chart_1.csv',function(csv) {
$('#chart_1')。highcharts({
图表:{
类型:'列'
},
数据:{
csv :csv
}
});
});

$ .get('chart_2.csv',function(csv){
$('#chart_2')。highcharts({
chart:{
type :'列'
},
数据:{
csv:csv
}
});
});


解决方案使用 setInterval ,把你的ajax放到函数中。

pre $函数function1(){
//做你的AJAX这里的东西
}
setInterval(function1,300000); // 300000 MS == 5分钟

如果您想在加载中显示图形,请使用:

  $(window).load(function(){
// ajax函数
}

Reference。


I have 2 Charts (using Highcharts) with different data on one page. The data to visualize comes from CSV files. My Code works so far, and the Charts show the CVS content visualized. But: I need to reload the CSV every 5 Minutes, cause new data gets written in these CSV files every 5 Minutes. How do I perform that reload in the best way? My code to generate the 2 Charts:

$.get('chart_1.csv', function(csv) {
 $('#chart_1').highcharts({
    chart: {
        type: 'column'
    },
    data: {
        csv: csv
    }
 });
});

$.get('chart_2.csv', function(csv) {
 $('#chart_2').highcharts({
    chart: {
        type: 'column'
    },
    data: {
        csv: csv
    }
 });
});

解决方案

Use setInterval, put your ajax inside the function.

function function1() {
    //do your AJAX stuff here
}
setInterval(function1, 300000); //300000 MS == 5 minutes

If you want to show the graph on load use this:

$(window).load(function() {
//ajax function here
}

Reference.

这篇关于Highcharts - 加载并刷新csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆