I have sorted out most of the problems with that code by doing the following:
changed now += updateInterval
to now = new Date().getTime();
in the update(_data)
function so that new data points always have the current time.
Added now -= totalPoints * updateInterval;
at the beginning of the initData()
function so that the current time is at the right end of the x-axis instead of the left end.
change the tickFormatter
function to:
tickFormatter: function (v, axis) {
var date = new Date(v);
if (date.getSeconds() == 0) {
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
return hours + ":" + minutes;
} else {
return "";
}
},
and and directly call GetData();
at the end of the document.ready()
function (instead of the setTimeout(GetData, updateInterval);
But I would like to see if there is some way I could smooth out the chart? Would it be possible to create a smooth flowing chart similar to the one on the flot charts homepage using Ajax? I realise its been redrawn every time it updates so what about if I provided an array of data ahead of time on the chart as in to give it a head start then just keep updating to keep it smooth?