2

I'm using dc.js and crossfilter to create 3 rowcharts from a csv. The first two are straighforward but the third one needs to have a dimension set to multiple columns of my input csv, so i've restructured the data so that for every required column (with a value present) for that row, a new duplicate row is created with that columns value inputted under a new column. See below;

old structure:
ID --- rowchart1 --- rowchart2 ---- rowchart3 ----- rowchart3 ----- rowchart3 -----
1
2
3

new structure:
ID --- rowchart1 --- rowchart2 ---- newRowchart3
1
2
2
2
3
3

It all works fine as i'm able to set the rowchart to this new constructed column but i'm having trouble getting the original counts to be displayed in the other two. Effectively i'm getting duplicate counts in those other row charts.
Is there a way to group by a unique id so it only counts those unique ids instead of every row count?
many thanks

user3836998
  • 65
  • 1
  • 8

1 Answers1

1

Please see: Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?

Your example is a slightly simpler example because you don't have an array for "rowchart3" values but the solution could still work for you.

The answer includes a jsfiddle that demonstrates how to manually manage the categories in the chart. You would need to change

function reduceAdd(p, v) {
   if (v.topics[0] === "") return p;    // skip empty values
   v.topics.forEach (function(val, idx) {
      p[val] = (p[val] || 0) + 1; //increment counts
   });
   return p;
}

to something like

function reduceAdd(p, v) {
   if(v.rowhart3a != "")
      p[v.rowchart3a] = (p[v.rowchart3a] || 0) + 1; //increment counts

   if(v.rowhart3b != "")
      p[v.rowchart3b] = (p[v.rowchart3b] || 0) + 1; //increment counts

   if(v.rowhart3c != "")
      p[v.rowchart3c] = (p[v.rowchart3c] || 0) + 1; //increment counts

   return p;
}

I hope this helps. -DJ

Community
  • 1
  • 1
DJ Martin
  • 2,579
  • 20
  • 24
  • Hi i've got a slightly amended problem now where i need the actual numbers inside those rowChart3 columns rather than counts. How would i add those? Additionally what is it i set the dimension to if i havent got an array like in the linked example – user3836998 Jul 28 '14 at 14:23