两个带有同步十字准线的“dygraphs” [英] Two `dygraphs` with synchronized crosshair
问题描述
我已经使用自定义选项 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屋!