Horizontal line to show average in dygraph

后端 未结 2 1133
耶瑟儿~
耶瑟儿~ 2021-01-13 06:48

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 horizont

相关标签:
2条回答
  • 2021-01-13 07:02

    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();       
     }});
    
    0 讨论(0)
  • 2021-01-13 07:15

    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.

    0 讨论(0)
提交回复
热议问题