简体   繁体   中英

Graph for data updated every 30 minutes

I make weather station which uploads data to my MySQL database every 30-60 minutes. 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. 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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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