Home > Net >  How to select certain time period in d3 js?
How to select certain time period in d3 js?

Time:01-07

Here is a radial line chart I found online: https://bl.ocks.org/tlfrd/fd6991b2d1947a3cb9e0bd20053899d6

I want to visualize the data between Oct 2016 to Feb 2017. How should I do that for this code?

Thanks!!

CodePudding user response:

Modify your code as the following:

function(error, data) {
  if (error) throw error;

  const fromTime = new Date('2016-10-01').getTime();
  const toTime = new Date('2017-03-01').getTime();

  data = data.filter(d => {
    const time = d.Date.getTime();
    return time >= fromTime && time < toTime;
  });

  x.domain(d3.extent(data, function(d) { return d.Date; }));
  y.domain(d3.extent(data, function(d) { return d.Close; }));
  ...
}
  •  Tags:  
  • Related