Highcharts - load and refresh csv

[亡魂溺海] 提交于 2020-01-06 08:28:11

问题


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
    }
 });
});

回答1:


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.




回答2:


There is a way to read updated csv files every time. Default, ajax requests use cache. You can change that by using: $.ajaxSetup({ cache: false }); This is the way to do it when using implicit ajax requests like $.get. Otherwise, just add "cache: false" in your ajax statements list.



来源:https://stackoverflow.com/questions/35218910/highcharts-load-and-refresh-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!