draw new data per second in flot
http://stackoverflow.com/questions/9393424/flot-graph-is-not-working-with-time-and-count
HTML
<script src="http://people.iola.dk/olau/flot/jquery.flot.js"></script>
<div id="placeholder" style="width:800px;height:300px;"></div>
<div id="balance"></div>
JavaScript
var data = [{
label: "test Data",
data: draw(),
lines: {
show: true,
fill: false,
fillColor: "rgba(249, 28, 61,0.3)",
lineWidth: 2.5
},
points: {
show: false
}
}];
var options = {
xaxis: {
/* mode: "time",
timeformat: "%H:%M" */
},
yaxis: {
/* min: -2,
max: 2 */
},
series: { lines: { show: true }, points: { show: false } },
grid: {
hoverable: true,
clickable: false
}
};
var plot = $.plot($("#placeholder"), data, options);
var array = [];
function draw(flg) {
var d = new Date(),
tz = d.getTimezoneOffset();
jsonUrl = 'https://gdax-inkymike.c9users.io/api'
$.getJSON(jsonUrl, function (jdata) {
array = [];
var trades = JSON.parse(jdata.tradeHistory).slice(-15);
console.log(trades.length);
var i = 0;
$.each(trades, function (key, val) {
//if (typeof val === 'number') {
//d = new Date(val - 5 * 60 * 1000);
/* if (array.length > 20) {
array.shift();
} */
var delta = ((val.balance / 0.0018) * 100) - 100;
array.push([val.trades, delta]);
//array.push([d.getTime() - tz * 60 * 1000, Math.random()]);
i++;
//}
});
$('#balance').html((trades.slice(-1))[0].balance + ' BTC');
}).done(function (jdata) {
data[0]["data"] = array;
$.plot($("#placeholder"), data, options);
});
}
setInterval(draw, 4000);