0

I'm working on a visualization tool for time series with multiple dimensions. To simplify my case, each data-point has a dimension on type, clusterId and a set of months:

    {
    type: "green", 
    clusterId:42, 
    months:[1392185580000, 1394604780000, 1397279580000]
    }, {
    type: "red", 
    clusterId:43, 
    months:[1392185580000]
    }

Now I would like to show the dates in a dc.barChart, which shows the months of all datasets as keys(bars), and the number of observations of each month as value of the bar. In the given case, it would result in 3 bars, the first one with a height of 2, and the other with a height of 1.

How can I create this dimension and implement the grouping/reducing function?

You don't have to worry about filtering by this dimension, I already have a custom filter for this dimension. The only thing is displaying the bars on the barChart.

user2440437
  • 121
  • 1
  • 6
  • I found the answer for my question [here](http://http://stackoverflow.com/questions/17524627/is-there-a-way-to-tell-crossfilter-to-treat-elements-of-array-as-separate-record?rq=1) – user2440437 Jun 24 '14 at 18:33

1 Answers1

0

If i get this correctly, you need some code, that outputs: 1392185580000: 2, 1394604780000: 1, 1397279580000:1?

arr.forEach(function(d) {
    d.months.forEach(function(month) {
        if (!store.hasOwnProperty(month)) {
            store[month]=0;
        }
        store[month]++;
    });
});

demo fiddle

Imperative
  • 3,138
  • 2
  • 25
  • 40
  • Thank you, but I have to use the crossfilter and dc.js library for my purposes. But now I've found a similar question with a solution that made it. Thanks anyway – user2440437 Jun 24 '14 at 18:31