javascripthighchartsdc.jscrossfilter

How to use .top() method in a crossfilter group with nested values


I am using a group of crossfilter.

When the values in a crossfilter group are like this:

{ key:"A", value: 2 }
{ key:"B", value: 5 }
{ key:"C", value: 1 }

Then group.top(2) returns the top 2 key value pairs based on the value i.e., ({key:"B", value: 5}, {key:"A", value: 2} )

But when the group is like this:

{ key: "A", value: {count:2} }
{ key: "B", value: {count:5} }
{ key: "C", value: {count:1} }

Then group.top(2) returns the top 2 key value pair based on key ({key: "A", value: {count:2}}, {key: "B", value: {count:5}})

I have group like this:

{ key: "A", value: {count:2} }
{ key: "B", value: {count:5} }
{ key: "C", value: {count:1} }

And I want the top 2 key value pairs to be returned on the basis of value's count. The output should be like this:

{ key: "B", value: {count:5} }
{ key: "A", value: {count:2} }

How can I achieve this?


Solution

  • group.order()

    Specifies the order value for computing the top-K groups. The default order is the identity function, which assumes that the reduction values are naturally-ordered (such as simple counts or sums).

    group.order(v => v.count)