d3.js sorting by rollup field

前端 未结 3 797
面向向阳花
面向向阳花 2021-01-21 08:24

I am having a JSON data and i want to group by a field and then sort by the count.

var data = [{\"Name\":\"Ravi\",\"Country\":\"India\"},
            {\"Name\":         


        
3条回答
  •  无人及你
    2021-01-21 08:56

    No, there is no built-in function giving the result you are after. d3.nest() does have a methode nest.sortValues() which will sort the leaf elements of nested data, but this is meaningless in your case since you did apply .rollup() leaving you with just one leaf per key. As you already mentioned, the way to go is using Array.prototype.sort().

提交回复
热议问题