使用 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 值。希望我能将其他人从我所经历的挫败感中拯救出来。
I am trying to sync the crosshair across three flot charts. I haven't been able to find any examples with the one exception of a somewhat similar example in the comment section of the crosshair.js file. Here is a snippet of my code, I am trying to initialize the plots here. Could someone please tell me what I am doing wrong?
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);
});
Turns out there are two problems with the above code, one is the grid: {hoverable: true}, statement is missing from the options for each of the plots. The other is the setCrosshair() function expects the full position variable not just the x value stored in pos.x. Hopefully, I can save someone else from the frustration I experienced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论