簡體   English   中英

在dygraph中顯示平均值的水平線

[英]Horizontal line to show average in dygraph

我正在嘗試向dygraph添加一條水平線,它已經顯示了我的時間序列數據。

我有完整數據的平均值,我希望在dygraph上顯示為靜態水平線。

有誰知道如何做到這一點。

我已經檢查過以下鏈接: http//dygraphs.com/tests/highlighted-region.html view-source: http//dygraphs.com/tests/crosshair.html

必須有一些簡單的解決方案

正如前面提到的danvk ,嘗試在"new Dygraph()"調用中指定"underlayCallback"選項。 使用HTML Canvas上下文繪制線條。

示例如下:( 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