我用绘制图表海军报实时曲线图。
$(function () {
var data = [];
var dataset;
var totalPoints = 100;
var updateInterval = 1000;
var now = new Date().getTime();
function GetData() {
if (data.length > totalPoints) {
data.shift();
}
var y = Math.random() * 100;
var temp = [now += updateInterval, y];
data.push(temp);
}
var options = {
series: {
lines: {
show: true,
lineWidth: 1.2,
fill: true
}
},
xaxis: {
mode: "time",
tickSize: [2, "second"],
tickFormatter: function (v, axis) {
var date = new Date(v);
if (date.getSeconds() % 20 == 0) {
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return hours + ":" + minutes + ":" + seconds;
} else {
return "";
}
},
axisLabel: "Time",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 10
},
yaxis: {
min: 0,
max: 100,
tickSize: 5,
tickFormatter: function (v, axis) {
if (v % 10 == 0) {
return v + "%";
} else {
return "";
}
},
axisLabel: "CPU loading",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 12,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 6
},
legend: {
labelBoxBorderColor: "#fff"
},
grid: {
backgroundColor: "#000000",
tickColor: "#008040"
}
};
$(document).ready(function () {
GetData();
dataset = [{
label: "CPU",
data: data,
color: "#00FF00"
}];
$.plot($("#placeholder"), dataset, options);
function update() {
GetData();
$.plot($("#placeholder"), dataset, options)
setTimeout(update, updateInterval);
}
update();
});
});
我更新图表每间隔。 问题是图总是开始从左边绘制。 我希望图形开始从右侧绘制,并保持向,因为它得到更新每个间隔向左移动。
我试图将数据作为[null, null]
但它抛出异常,在控制台上。
这里更好的想法?
小提琴