简体   繁体   English

每30分钟更新一次数据的图表

[英]Graph for data updated every 30 minutes

I make weather station which uploads data to my MySQL database every 30-60 minutes. 我制作了气象站,每30-60分钟将数据上传到我的MySQL数据库中。 How to make on example temperature plot for a week on my website? 如何在我的网站上制作一周的示例温度图? I've looked for such option in Highcharts but I don't know does it is possible. 我已经在Highcharts中寻找了这样的选择,但我不知道这是可能的。 Date and time is saved in database as timestamp. 日期和时间作为时间戳保存在数据库中。

他们有一个专门针对不规则时间间隔的时间数据的示例: http : //www.highcharts.com/demo/spline-irregular-time

Get your data from database for last week, then preprocess in backend to fit Highcharts data format, and as result you should have something like this: 从上周的数据库中获取数据,然后在后端进行预处理以适合Highcharts数据格式,因此您应该具有以下内容:

var myData = [
                [1388534400000, 12],
                [next_timestamp, next_value],
                [another_timestamp, another_value],
                ...
             ]

Now you can use that data to generate chart: 现在您可以使用该数据生成图表:

$("#container").highcharts({
    series: [{
        data: myData
    }]
})

Note : timestamps are in milliseconds. 注意 :时间戳以毫秒为单位。

Now to update chart every 30minutes, just create call some AJAX call to get new data from the server: 现在要每30分钟更新一次图表,只需创建调用一些AJAX调用即可从服务器获取新数据:

setInterval(function() {
    $.getJSON('path/to/data', function(myData) {
        $("#container").highcharts().series[0].setData(myData);
    });
}, 30 * 60 * 1000); // 30minutes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM