Created
May 22, 2011 07:05
-
-
Save rsumbaly/985239 to your computer and use it in GitHub Desktop.
Yes, I've started writing JS now :|
This file contains 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
$( function () { | |
globalData = []; | |
var placeholder = $("#placeholder"); | |
$.plot(placeholder, [[]], options); | |
var num_points = 300; | |
function onDataReceived(data_point) { | |
globalData.push(data_point.data + ( Math.random() * 10)); | |
var res = []; | |
for (var i = 0; i < globalData.length; ++i) { | |
res.push([i, globalData[i]]) | |
} | |
$.plot(placeholder, [ res ], options); | |
} | |
function plotData() { | |
if ( globalData.length > num_points) { | |
globalData = globalData.slice(1); | |
} | |
var jqxhr = $.ajax({ | |
url: "/pig.json", | |
method: 'GET', | |
dataType: 'json', | |
success: onDataReceived | |
}); | |
} | |
var updateInterval = 1000; | |
$("#updateInterval").val(updateInterval).change( function () { | |
var v = $(this).val(); | |
if (v && !isNaN(+v)) { | |
updateInterval = +v; | |
if (updateInterval < 1) | |
updateInterval = 1; | |
if (updateInterval > 2000) | |
updateInterval = 2000; | |
$(this).val("" + updateInterval); | |
} | |
}); | |
// setup plot | |
var options = { | |
series: { | |
shadowSize: 0 | |
}, | |
yaxis: { | |
min: 0, | |
max: 50 | |
}, | |
xaxis: { | |
show: false | |
} | |
}; | |
function update() { | |
plotData(); | |
setTimeout(update, updateInterval); | |
} | |
update(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What are you trying to plot?