Created
July 13, 2012 18:40
-
-
Save gidili/3106566 to your computer and use it in GitHub Desktop.
flot_realtime_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var plot = null; | |
var flotOptions = { yaxis: { min: -30, max: 125 }, xaxis: { min: 0, max: 100, show: false }, series: { shadowSize: 0 }, grid: { backgroundColor: { colors: ["#fff", "#eee"] } } }; | |
function refreshChart(data) | |
{ | |
if(data != null){ | |
var points = []; | |
for(var i=0; i< data[0].length; i++){ points.push([data[0][i], data[1][i]]); } | |
plot.setData([{data: points, label: "mV", color: "#4AA02C"}]); | |
plot.setupGrid(); | |
plot.draw(); | |
} | |
} | |
function getDataset() | |
{ | |
$.ajax({type : 'GET', | |
url : '/getDataset', | |
dataType: 'json', | |
timeout : 5000, | |
success : function(data, textStatus) { refreshChart(data); }, | |
error : function(xhr, textStatus, errorThrown) { alert("Error getting dataset!"); } | |
}); | |
} | |
$(document).ready(function(){ | |
plot = $.plot($("#placeholder"), [{data: [], label: "mV", color: "#4AA02C"}], flotOptions); | |
setInterval(getDataset, 100); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment