Question

I'm trying to use the Crossfilter example site as a start for my desired graph, but am struggling with creating a non grouped graph that interacts with a grouped graph.

My data is a list of unique employee records:

employee,cnt
john,3
bill,15
fred,30
jill,6
...

I want one graph to show the cnt field grouped by value, analogous to the example's Distance graph. The next graph I want would have a bar for each employee, but instead of grouping them by employee value, I want the graph instead to simply show the cnt value.

Here's what I got going so far; however, this does group-by on both graphs:

// ...

var crossData = crossfilter(data),
    all = crossData.groupAll(),
    cnt = crossData.dimension(function(d) { return d.cnt; }),
    cnts = cnt.group(),
    emp = crossData.dimension(function(d) { return d.employee; }),
    emps = emp.group();

var charts = [  
  barChart()
      .dimension(cnt)
      .group(cnts)
    .x(d3.scale.linear()
      .domain([0, 15])
      .rangeRound([0, 920])),

  barChart()
      .dimension(emp)
      .group(emps)
    .x(d3.scale.ordinal().rangePoints([0, 920])
      .domain(data.map(function(d) { return d.employee; })))  
];

// ...
Was it helpful?

Solution

Make your "emps" group sum by cnt, like this:

emps = emp.group().reduceSum(function (d) { return d.cnt; });

That will give you the sum of the cnt field for each employee. Since you only have one record per employee, you'll just get the value of the cnt field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top