两个带有同步十字准线的“dygraphs” [英] Two `dygraphs` with synchronized crosshair

查看:136
本文介绍了两个带有同步十字准线的“dygraphs”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用自定义选项 verticalCrosshair实现了两个 dygraphs :true 此处:



以获得灵感。


I have implemented two dygraphs with custom option verticalCrosshair : true here:

https://rawgit.com/danielkrizian/dygraphs/master/tests/synchronize-Crosshair.html

When I hover over any of the graphs at a particular x point, I want all graphs to display the vertical crosshair at that point. So far I've been able to get this working on the top graph (gs[0]) like this:

highlightCallback: function(e, x, pts, row) {
  var sel = gs[0].getSelection();
  gs[1].setSelection(sel);
},

Nothing happens when I hover over the bottom graph. How to generalize it with for loop over all graphs?

解决方案

You should put the dygraphs objects in an array and loop over it in your highlightCallback, updating the selection in all the dygraphs other than the one generating the event.

One complication is that highlightCallback doesn't get the dygraph object as a parameter. This is an oversight in the API which I hope to fix in dygraphs 2.0. You can work around it by capturing the relevant Dygraph object in a closure when you set highlightCallback.

See the synchronize demo for some inspiration.

这篇关于两个带有同步十字准线的“dygraphs”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆