formalreasoning
formalreasoning

Reputation: 113

How to create x-axis range groups with Crossfilter and dc.js?

Here is a fiddle to help show what I'd like to do: http://jsfiddle.net/m4x7o5of/

I have a set of records, each with a float value. For example:

var records = [{name: 'record1', value: 1.34563}, ..., {name: 'record5000', value: 0.62974}];

I'd like to create a barchart in dc.js that plots the records on the x-axis in range buckets, e.g x-number of records with value between 0 and .5, y-number of records between .5 and 1, z-number of records between 1 and 1.5, and so on.

I'm using an ordinal scale so that I can divide the set of records into 5ths, but I can't figure out how to get the records grouped together in the ranges like I described. In the linked fiddle, only the records with a value that matches the plotted ordinals will get displayed right now.

Is it even possible to group the records like this? Any help would be appreciated.

Upvotes: 0

Views: 815

Answers (1)

Ethan Jewett
Ethan Jewett

Reputation: 6010

dimension.group takes a function that you can use to derive the group key. So dimension.group(function(d) { return Math.floor(d); }); will give you group keys of 0, 1, 2, 3, 4, 5, 6, 7, and 8 for your data set. You'll just need to construct a function that returns the values you want based on the values in your data set. Is that what you're looking to do?

Upvotes: 2

Related Questions