Dygraph setAnnotations with repeated x values

早过忘川 提交于 2021-01-28 05:40:40

问题


I am using Dygraph 2.0. I have a csv with repeated x values and when I call setAnnotations function with this x value drawing repeated annotation.

Example csv:

x,val1,val2,val3
0,1,1,3
1,2,3,5
1,3,3,3
2,4,5,5
3,1,2,2

When I set annotation on x = 1, dygraph draw 2 annotation. I need to known if exist any way that say to dygraph that drawing only one annotation


回答1:


I am sure it is not the best option but right now it is the solution I have figured out and maybe it works for you

http://jsfiddle.net/wn43LLv7/1/

$(document).ready(function () {
    
var csv = [[0,1,1,2],[1,2,3,3],[1.0001,4,4,4],[2,2,2,2]];

     var g = new Dygraph(
        document.getElementById('graph'),
        csv,
        {
          labels: ['x', 'val1', 'val2', 'val3' ]
        }
      );
g.ready(function() {
    g.setAnnotations([
    {
      series: "val2",
      x: "1",
      shortText: "A"
    }
    ]);
  });
  })
.thinborder { border-width: 1px; border-spacing: 0px; border-style: solid; border-color: black; border-collapse: collapse; }

.thinborder td, #workarea #independent-series .thinborder th { border-width: 1px; padding: 5px; border-style: solid; border-color: black; }

.dygraph-annotation
{
      font-size: 14px;
    left: 217.5px;
    top: 79.1111px;
    width: 16px;
    height: 16px;
    position: absolute;
    background-color: red;
    border-color: rgb(64, 0, 128);
    color: white !important;
    padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://dygraphs.com/dygraph.js"></script>
<div id="graph" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>


来源:https://stackoverflow.com/questions/44007718/dygraph-setannotations-with-repeated-x-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!