0

I am trying to create a bar chart (cross filter and dc js) to show how many people (unique) participated in an event

[ {"Year: 2015" , "Name:Person1"}, {"Year: 2015" , "Name:Person2"}, {"Year: 2015" , "Name:Person3"}, {"Year: 2015" , "Name:Person1"}, {"Year: 2015" , "Name:Person1"}, {"Year: 2016" , "Name:Person4"}, {"Year: 2016" , "Name:Person4"}, {"Year: 2016" , "Name:Person1"}, ] 

I am plotting Year on X axis and Count on Y axis. Right now with Reduce count on Year I get

Year: 2015 Count:3 -> person 1,2,3 Year: 2016 Count:2 -> person 1,4 

Sample code

yeardimension.group().reduceCount(function(d) { return d.year }) 

I want to get unique value and expected value

Year: 2015 Count:5 Year: 2016 Count:3 

How can I achieve this in cross filter and dc js?

1
  • 1
    It looks like your expected and received values are reversed in your question - the unique counts are 3 and 2, and reduceCount (which doesn't take a parameter btw) returns 5 and 3, no? Commented Apr 11, 2016 at 13:23

1 Answer 1

1

You would need to build a custom reducer, which is quite complex. There is an example here that gets at the right idea, though it will not be very fast and will break for certain keys as not all JS strings are valid property names: Crossfilter reduce :: find number of uniques

You can use Reductio's exception aggregation functionality to build fast and robust versions of these reducers easily. Or you may want to keep an eye on Universe, which aims to make this easy in a different way, using Reductio and Crossfilter under the covers.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your reply.I indeed tried adding custom java script but it did not work
thanks for your reply.I indeed tried adding custom java script but it did not work . Is it because my dimension is on Year and while trying to reduce it i am trying to get uniques for Name. My bar chart dimension and group are on year and count for year so even after putting the custom js logic, cross filter still tries to get count for all records for particular year
Please share the complete code that replicates your problem. Even better would be to create a working example using JSfiddle or Codepen.
The Exception aggregation works fine for me. Thanks for the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.