How to disable some streams by default in a nvd3 Simple Line Chart?

前端 未结 4 847
-上瘾入骨i
-上瘾入骨i 2020-12-30 01:47

I have several lines and I know that clicking on the \"dot\" in the legend will hide/show it.

However, I need to start with some of the lines being disabled and not

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 02:20

    You could start out with a hidden chart and try something like this:

    // Array of series you want to hide
    var hidden = [0, 2];
    
    // Dispatch click event to each element
    var e = document.createEvent('UIEvents');
    e.initUIEvent('click', true, true);
    d3.select('.nv-legend')
      .selectAll('.nv-series')
      .filter(function(d, i){return hidden.indexOf(i) !== -1;})
      .node()
      .dispatchEvent(e);
    

    Once this finishes, unhide your chart and the series will be disabled.

提交回复
热议问题