简体   繁体   English

在dygraph中显示平均值的水平线

[英]Horizontal line to show average in dygraph

I am trying to add a horizontal line to dygraph which already show my time series data. 我正在尝试向dygraph添加一条水平线,它已经显示了我的时间序列数据。

I have average of the complete data which I want to show as a static horizontal line on dygraph. 我有完整数据的平均值,我希望在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 我已经检查过以下链接: http//dygraphs.com/tests/highlighted-region.html view-source: http//dygraphs.com/tests/crosshair.html

There must be some simple solution to this 必须有一些简单的解决方案

As danvk mentioned before , try specifying the "underlayCallback" option within your "new Dygraph()" call. 正如前面提到的danvk ,尝试在"new Dygraph()"调用中指定"underlayCallback"选项。 Use HTML Canvas context to draw the line. 使用HTML Canvas上下文绘制线条。

Example below: (xmin and xmax are your unix epoch time in milliseconds) 示例如下:( xmin和xmax是你的unix纪元时间,以毫秒为单位)

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();       
 }});

您可以选择使用底层回调(ala http://dygraphs.com/tests/highlighted-region.html )或添加第二个常量数据系列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM