试试这个http://jsfiddle.net/Bvpft/16/
在 Chrome 和 FireFox 中测试。它刷新并重新下载图像,但不确定它应该做什么。
HTML
<!DOCTYPE html>
<body>
<div id="graph" >
<object type="text/html" style="width:100%; height:100%; margin:1%;" data="">
</object>
</div>
</body>
Javascript
$(document).ready( function() {
var graph = $('#graph'),
uri = 'https://api.cosm.com/v2/feeds/120687/datastreams/sensor_reading.png?',
params = {
width: 740,
height: 150,
colour: '#0055ff',
duration: '5minutes',
legend: 'Vibration measure 0 -> 1024 ',
title: 'Foosball Vibrations - 5 Minutes',
show_axis_labels: 'true',
detailed_grid: 'true',
scale: 'manual',
max: 75,
timezone: 'Mountain Time (US & Canada)'
};
var updateGraph = function() {
var data = uri + $.param(params);
graph.empty();
graph.append($('<object/>')
.prop({'type': 'text/html', data: data})
.css({'width': '100%', 'height': '100%'}))
};
updateGraph();
setInterval (updateGraph, 1000);
});
已编辑 - 更改为图像,不闪烁,添加无缓存(在 IE10、Chrome 和 FireFox 中测试):http: //jsfiddle.net/JAYDb/4/
HTML
<div id="graph" ></div>
CSS
#graph {
background-color:#C0C0C0;
margin: 0 auto;
min-height: 200px ;
min-width: 750px ;
display: inline-block;
}
#graphObject{
display: block;
width: 100%;
}
Javascript
$(document).ready( function() {
var uri = 'https://api.cosm.com/v2/feeds/120687/datastreams/sensor_reading.png?',
params = {
width: 740,
height: 150,
colour: '#0055ff',
duration: '5minutes',
legend: 'Vibration measure 0 -> 1024 ',
title: 'Foosball Vibrations - 5 Minutes',
show_axis_labels: 'true',
detailed_grid: 'true',
scale: 'manual',
max: 75,
timezone: 'Mountain Time (US & Canada)'
};
var data = uri + $.param(params),
graph = $('#graph'),
obGraph = $('<img/>').prop({'id': 'graphObject'});
var updateGraph = function() {
var date = new Date(),
src = data + '&' + date.getTime();
obGraph.prop('src', '');
obGraph.prop('src', src);
};
graph.empty().append(obGraph);
updateGraph();
setInterval (updateGraph, 1000);
});