0
votes

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
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?Gordon

1 Answers

1
votes

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.