Reputation: 2620
I trying to plot a lineChart and I want to aggregate data by Month. I am using dataset from crossfilter documentation with slight modification in date.
This is how my dataset looks like:
var data = [
{date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-07-10T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-07-15T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-06-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-06-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-05-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-07-17T16:14:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
{date: "2011-05-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-12-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
{date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
];
I want to group total by Month-Year. My Data Group is returning total based on date instead of Month.
In my graph, July 10, 15 and 17 are plotted as different point. I want to combine them all into July-2017 points. How do I acheive that ? Any pointers? Thanks All!
here is a fiddle: https://jsfiddle.net/usingh2buffaloedu/8u0etnwd/
Upvotes: 1
Views: 1107
Reputation: 166
I've had issues with time rendering in dc.js, but in your example the key is to get the month values in your dimension.
var dateDimension = facts.dimension(function (d) {return d3.time.month(d.newDate); });
See the updated fiddle (https://jsfiddle.net/ury1k1bs/1/)
I think the .round() chart method is only useful for brushing, not for rendering.
For more see the time interval example provided by dc.js... http://dc-js.github.io/dc.js/examples/switching-time-intervals.html
Upvotes: 3