I am trying to add a horizontal line to dygraph which already show my time series data.
I have average of the complete data which I want to show as a static horizontal line on dygraph.
Does anyone know how to do that simply.
I already checked following links: http://dygraphs.com/tests/highlighted-region.html view-source:http://dygraphs.com/tests/crosshair.html
There must be some simple solution to this
Add a horizontal average line to a chart with a helper column. Note: Click to know more about applying the same formla to entire column, or applying the exact same formula/value to entire column without cell number incrementing. 2. And then select this range and choose one chart format that you want to insert,...
A rolling average can be set using the text box in the lower left-hand corner of the graph (the showRoller attribute is what makes this appear). Also note that we've explicitly set the size of the chart div. Error Bars Another significant feature of the dygraphs library is the ability to display error bars around data series.
If a moving average is being displayed, dygraphs will compute the standard deviation of the average at each point. I.E. σ = sqrt( (σ12+ σ22+ ... + σn2) / n )
The Dygraph automatically chose two different, easily-distinguishable colors for the two data series. The labels on the x-axis have switched from days to months. If you zoom in, they'll switch to weeks and then days. Some heuristics are used to determine a good vertical range for the data.
As danvk mentioned before, try specifying the "underlayCallback"
option within your "new Dygraph()"
call. Use HTML Canvas context to draw the line.
Example below: (xmin and xmax are your unix epoch time 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();
}});
Your options are either to use an underlay callback (ala http://dygraphs.com/tests/highlighted-region.html) or to add a second, constant data series.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With