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
Since this question comes up now and then and it would be nice to have a decent example, I went back to NorthSide's question from a while back and fixed up the fiddle.
dc.js - add drop down to select date range
We'll define a second time dimension so that the charts are affected by it.
In this example we set the number of days as the option value, and then use that to calculate the date:
d3.select('#myDropDown').on('change', function(){
var nd = new Date(now);
nd.setDate(nd.getDate() - +this.value);
filterDimension.filterRange([nd, now]);
dc.redrawAll();
});
http://jsfiddle.net/gordonwoodhull/400wd2nd/16/
There are more intelligent ways to calculate a month back and so on, but hopefully this is enough to get you started.