The horizontal line to show the average value in the diagram

I am trying to add a horizontal line to a dygraph that already shows time series data.

I have an average of the total data that I want to show as a static horizontal line in the graph.

Does anyone know how to do this simply.

I already checked the following links: http://dygraphs.com/tests/highlighted-region.html view-source: http://dygraphs.com/tests/crosshair.html

There must be some simple solution for this

+4
source share
2 answers

Like the danvk mentioned above , try specifying the "underlayCallback" parameter in your call to "new Dygraph()" . Use the HTML Canvas context to draw a line.

Example below: (xmin and xmax are the times of your unix era in milliseconds)

 var yavg= 50, xmin=1357016400000, xmax=1359694800000; new Dygraph(document.getElementById('graph1'), data,{ (....other options....), underlayCallback:function(ctx,area,dygraph){ var xl = dygraph.toDomCoords(xmin,yavg); var xr = dygraph.toDomCoords(xmax,yavg); ctx.strokeStyle= 'green'; ctx.beginPath(); ctx.moveTo(xl[0],xl[1]); ctx.lineTo(xr[0],xr[1]); ctx.closePath(); ctx.stroke(); }}); 
+6
source

Your options are to use a subclass callback (ala http://dygraphs.com/tests/highlighted-region.html ) or add a second, persistent series of data.

+1
source

All Articles