Skip to content

Instantly share code, notes, and snippets.

@rsumbaly
Created May 22, 2011 07:05
Show Gist options
  • Save rsumbaly/985239 to your computer and use it in GitHub Desktop.
Save rsumbaly/985239 to your computer and use it in GitHub Desktop.
Yes, I've started writing JS now :|
$( 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();
});
@afeinberg
Copy link

What are you trying to plot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment