我在x轴上有时间序列,在y轴有一些功率瓦特信息。第一次占位符和概述图显示正常。当我在占位符图中选择概览图值的变化区域时,它会显示或绘制任何一行。
JavaScript代码:
function graph(jsonarray) {
var options = {
yaxis: {
/* color:"#00FF00",
tickColor:"#FF0000",font: "sans 9px",reserveSpace: true,
axisLabel: "Watts",
axisLabelUseCanvas: true*/
},
xaxis: {
mode: "time",
timeformat: "%H:%M:%S",
minTickSize: [1, "second"]
},
lines: {
show: true
},
points: {
show: false,
hoverable: true
},
grid: {
show: true,
hoverable: true,
clickable: true,
backgroundColor: {
colors: ["#fff", "#eee"]
}
},
legend: {
show: false,
type: "canvas",
position: "se",
backgroundColor: "#ff4",
backgroundOpacity: 0.35
},
selection: {
mode: "xy"
}
}
var d2 = JSON.stringify(jsonarray);
var d1 = eval(jsonarray);
globalJson = d1;
var data = [];
for (var i = 0; i < d1.length; i++) {
var temp = (d1[i].datetime.time) + 19800000; //GMT 5:30 is added to get actul time
data.push([temp, d1[i].watts]);
}
var plot = $.plot($("#placeholder1"), [data], options);
var overviewoptions = {
legend: {
show: false
},
series: {
lines: {
show: true,
lineWidth: 1
},
shadowSize: 0
},
yaxis: {},
xaxis: {
mode: "time",
timeformat: "%H:%M:%S",
minTickSize: [1, "second"]
},
grid: {
color: "#999"
},
selection: {
mode: "xy"
}
}
var overview = $.plot("#overview", [data], overviewoptions);
// now connect the two
$("#placeholder1").bind("plotselected", function (event, ranges) {
// clamp the zooming to prevent eternal zoom
if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) {
ranges.xaxis.to = ranges.xaxis.from + 0.00001;
}
if (ranges.yaxis.to - ranges.yaxis.from < 0.00001) {
ranges.yaxis.to = ranges.yaxis.from + 0.00001;
}
// do the zooming
plot = $.plot("#placeholder1", trimData(eval(jsonarray), ranges.xaxis.from, ranges.xaxis.to),
$.extend(true, {}, overviewoptions, {
xaxis: {
min: ranges.xaxis.from,
max: ranges.xaxis.to
},
yaxis: {
min: ranges.yaxis.from,
max: ranges.yaxis.to
},
}));
// don't fire event on the overview to prevent eternal loop
overview.setSelection(ranges, true);
});
$("#overview").bind("plotselected", function (event, ranges) {
plot.setSelection(ranges);
});
return true;
}
下面是两个输出图像。 (抱歉无法附上(因为我没有10个声望)。 我找不到任何线索,为什么当x和y轴值发生变化而没有画线时会发生这种情况。
答案 0 :(得分:1)
您的原始数据以如下数组形式提供:
[[time, watts], ...]
如果您的评论准确无误,那么trimData的输出似乎完全不同。对象数组将被解释为单独的系列,如果您尝试将它们绘制为一条线,则会产生空结果。
您应该修复trimData以匹配原始格式或完全跳过它,因为Flot将仅显示范围内出现的那些点。减少数据的唯一原因是,如果您有大量数据,并且担心性能。