Bob
Bob

Reputation: 671

dygraph vertical line

Is there a way to make a vertical line in the js graph library dygraph?

I am loading data and would like to put vertical lines like graphite does to show events

is there some special context to add vertical lines

enter image description here

Upvotes: 4

Views: 4476

Answers (3)

momo
momo

Reputation: 21

  g4.updateOptions({ pointClickCallback: function(event, p) {
    var div_vertical_style="top:0px;left:"+g4.toDomCoords(p.xval,-20)[0]+"px;width:1px;height:"+g4.plotter_.area.h+";background-color:black;position:absolute;";
    $("#graphdiv4").append("<div style="+div_vertical_style+"></div>")
   }}); 

//my idea , add div .....

Upvotes: 1

user1556842
user1556842

Reputation: 21

Here is a simple solution.

Use the crosshair demo (http://dygraphs.com/tests/crosshair.html) on the Dygraph site.

Once you disable the horizontal bar on the crosshair sample, you are getting a vertical bar.

Upvotes: 2

dcrosta
dcrosta

Reputation: 26258

You've probably figured this out by now, or stopped caring, but the way to do this is with a custom underlay (see http://dygraphs.com/tests/highlighted-region.html and http://dygraphs.com/tests/underlay-callback.html for examples). You provide an underlayCallback function when creating the graph, and it gets called with the canvas element, area (which helps with coordinate math), and a reference to the Dygraph object.

Upvotes: 8

Related Questions