使用 FLOT 在多个图表上同步十字线

发布于 2025-01-05 07:25:59 字数 1249 浏览 1 评论 0原文

我正在尝试在三个流程图上同步十字准线。除了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文