DC, Crossfilter dimension: multiple columns as different keys?

I have two date columns (startYear and endYear) for each of 50 apps. The earliest startYear is 1994 and the latest endYear is 2030.

I want to add a time widget bar chart into an existing DC dashboard. There will be one bar per year from 1994 to 2030 and each bar should show the number of apps in existence in that year. I'm aiming for the following data structure in my crossfilter group:

group(36) = [
{key:1994, value:1},
{key:1995, value:4},
{key:1996, value:5},
{key:1997, value:10},
{key:1998, value:30},
... etc
]

(Actually, the key will need to have a date data type, but you see what i mean.)

Normally I'd have a field called year and create a dimension on it. But actually there's no field with all year values from 1994 to 2030. So I'm making 'fake data'. Currently I'm creating fake fields, called 1994, 1995 etc by running this on my data:

data.forEach(function(d){
      for (var i=1994; i<2031; i++) {
        if (i>=d.start && i<=d.end) {
          d[i]=1;
        } else {
          d[i]=0;
        }
      }
}

I'm assigning 1 for apps that exist in that year, and 0 for those that don't. This works fine. But now I need to combine 36 fields into one dimension, making the 36 fields different keys of the dimension. On this bit I'm stuck. I keep getting: key: {1994:1, 1995:4, 1996:5 ... etc.} or similar with array. Latest effort:

var timeDimension = facts.dimension(function(d){ return {
  1994:d[1994], 1995:d[1995], 1996:d[1996], 1997:d[1997], 1998:d[1998], 1999:d[1999],
  2000:d[2000], 2001:d[2001], 2002:d[2002], 2003:d[2003], 2004:d[2004], 2005:d[2005],
  2006:d[2006], 2007:d[2007], 2008:d[2008], 2009:d[2009], 2010:d[2010], 2011:d[2011],
  2012:d[2012], 2013:d[2013], 2014:d[2014], 2015:d[2015], 2016:d[2016], 2017:d[2017]
}; });

Does anyone know if it's possible to combine multiple fields into a single dimension in this way? Maybe I need to change the fake data, eg to a single field array like [0,0,0,1,1,1,1...] for each app. But if I do that, how do I generate the dimension on years 1994-2030, when these don't exist anywhere?

My worst case scenario is to create extra rows, so each datapoint is repeated 35 times, for different years. I'd like to avoid this but don't see how.

Thanks for any help

Emma

链接地址: http://www.djcxy.com/p/32696.html

上一篇: 将大型数据集加载到crossfilter / dc.js中

下一篇: DC,Crossfilter维度:多列作为不同的键?