Search code examples
javascriptdygraphs

How to set selected range in range selector in dygraph


By default, dygraph select the whole date range in its range selector:

enter image description here

Is there an option to set the default selected range in dygraph? I've been searching for a while and can't find any similar problem as mine.

This is my desired output:

enter image description here


Solution

  • I thought you can only pass int values on dateWindow options of dygraph. It seems like it accepts Date object as well. I solved my issued by adding dateWindow option:

    new Dygraph(document.getElementById('#graph'), data, {
         labels: [ "x", "y" ],
         showRangeSelector: true,
         legend: 'always',
         dateWindow: [new Date("2021-06-01"), new Date("2021-06-25")]
    });
    

    NOTE: I'm changing the value of date object dynamically