Returning max value in a DC.js / Crossfilter group -


i wondering how return max value dc.js group.

for example:

  var datedim = data.dimension(function(d) {return d.page_id;});   var hits = datedim.group().reducesum(function(d) {return d.commodity_id;});  

this return bar chart plotting page_ids on x axis, against commodity_ids on y axis.

however, return amount of commodity_ids on particular page on y axis.

would accomplished similar max , min dimension functionality?

 var mindate = datedim.bottom(1)[0].page_id;  var maxdate = datedim.top(1)[0].page_id; 

apologies if description unclear.

thanks

i'll attempt @ least point in right direction.

the following lines of code return sum of commodity_id's grouped page_id:

    var datedim = data.dimension(function(d) {return d.page_id;});     var hits = datedim.group().reducesum(function(d){return d.commodity_id;}); 

if page had 3 commodities following commodity_id's: [ 1, 2, 5 ] reducesum return value 8 page (1+2+5=8); add each subsequent commodity_id until reached end of page.

assuming each entry in dataset contains commodity_id must counted, can away grouping , using reducecount since care total number of commodities per page:

    var hits = datedim.group().reducecount(); 

this count how many times each page_id appears in database, corresponds amount of commodity_id's there on page.

if see result of grouping can use:

    hits.all(); 

this return array of objects each object in array contains key , value. key corresponds page_id , value corresponds number of times page_id occurs in dataset.

at point, if you'd page_id maximum value, can use top() function. (group() contains top() function dimension(), returns group largest number of counts.) following how can access page_id entries in database (which should correspond amount of commodity_id's) , number of corresponding entries:

    var page_id_with_most_entries = hits.top(1)[0].key;     var number_of_entries = hits.top(1)[0].value; 

if haven't already, check out crossfilter.js api wiki:

https://github.com/square/crossfilter/wiki/api-reference

i have found annotated source code of dc.js nasdaq example shown on dc.js page helpful:

http://nickqizhu.github.io/dc.js/docs/stock.html

(just remove "docs/stock.html" link nasdaq example.)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -