在dygraph中显示平均值的水平线 [英] Horizontal line to show average in dygraph
问题描述
我正在尝试向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.
有没有人知道如何做到这一点。
Does anyone know how to do that simply.
我已经检查过以下链接:
http://dygraphs.com/tests/highlighted-region.html
view-source: http://dygraphs.com/tests/crosshair.html
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
推荐答案
As 前面提到的danvk ,请尝试在您的指定中指定underlayCallback
选项new Dygraph()
致电。使用HTML Canvas上下文绘制线条。
As danvk mentioned before, try specifying the "underlayCallback"
option within your "new Dygraph()"
call. Use HTML Canvas context to draw the line.
以下示例:
(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();
}});
这篇关于在dygraph中显示平均值的水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!