我正在尝试跨三个flot图表同步十字准线。我没有能够找到任何示例,除了crosshair.js文件的注释部分中的某个类似示例之外。这是我的代码片段,我正在尝试初始化这里的情节。有人可以告诉我我做错了吗?
var covariancePlot = $.plot($("#covarianceChartContainer"), [ 0,0 ], {crosshair: { mode: "x" }, xaxis:{ mode: "time"}});
var observationPlot = $.plot($("#observationChartContainer"), [ 0,0 ], {crosshair: { mode: "x" }, xaxis:{ mode: "time"}});
var collisionPlot = $.plot($("#collisionChartContainer"), [ 0,0 ], {crosshair: { mode: "x" }, xaxis:{ mode: "time"}});
$("#covarianceChartContainer").bind("plothover", function (event, pos) {
//sync crosshairs of the other two plots
observationPlot.setCrosshair(pos.x);
collisionPlot.setCrosshair(pos.x);
});
$("#observationChartContainer").bind("plothover", function (event, pos) {
//sync crosshairs of the other two plots
covariancePlot.setCrosshair(pos.x);
collisionPlot.setCrosshair(pos.x);
});
$("#collisionChartContainer").bind("plothover", function (event, pos) {
//sync crosshairs of the other two plots
observationPlot.setCrosshair(pos.x);
covariancePlot.setCrosshair(pos.x);
});
原来上面的代码存在两个问题,一个是网格:{hoverable:true},每个图的选项中都缺少语句。另一个是setCrosshair()函数需要完整的位置变量而不仅仅是存储在pos.x中的x值。希望我能从其经历的挫折中拯救别人。