【问题标题】:Horizontal line to show average in dygraph在 dygraph 中显示平均值的水平线
【发布时间】:2013-03-24 12:06:42
【问题描述】:

我正在尝试向已显示我的时间序列数据的 dygraph 添加一条水平线。

我有完整数据的平均值,我想在 dygraph 上显示为静态水平线。

有谁知道如何简单地做到这一点。

我已经检查了以下链接: http://dygraphs.com/tests/highlighted-region.html 查看源代码:http://dygraphs.com/tests/crosshair.html

必须有一些简单的解决方案

【问题讨论】:

    标签: javascript dygraphs


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      作为danvk mentioned before,尝试在"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();       
       }});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-31
        • 2011-01-30
        • 2017-04-12
        • 1970-01-01
        • 1970-01-01
        • 2013-02-26
        • 2018-05-19
        相关资源
        最近更新 更多