How to filter precisely on date?

前端 未结 2 1737
余生分开走
余生分开走 2021-01-22 19:25

I\'m using a lineChart to show created date (one field in my data), it works fine and I can select, but I need a more precise filter: only for items created today, this week, la

2条回答
  •  萌比男神i
    2021-01-22 20:10

    I added a feature to be able to select the current day, current week or current month:

      d3.select('#date_select').on('change', function(){ 
        var nd = new Date(), now = new Date();
        switch (this.value) {
          case "today":
            nd = d3.time.day(now);
            break;
          case "week":
            nd = d3.time.monday(now);
            break;
          case "month":
            nd = d3.time.month(now);
            break;
          default:
            nd.setDate(nd.getDate() - +this.value);
        }
        dim.filterAll();
        dim.filterRange([nd, now]);
        //did not work graph.replaceFilter(dc.RangedFilter(nd, now));
        graph.redrawGroup();
      });
    

    and the html being:

    
    

提交回复
热议问题