Horizontal line to show average in dygraph

谁说胖子不能爱 提交于 2019-12-01 18:49:24
user2916847

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!