Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
d3.nest rollup where keys are the categories of a column drilled down to a category in another column

I want to do a rollup by where the keys are the 'type' of the fruit 'banana'.

What I have:

var fruit_cnt = d3.nest()
        .key(function(d) {
            return d.fruit === "banana";
        })
        .rollup(function(o){
            return d3.sum(o, function(d){
                return d.count;
            });
        })
        .entries(dataset)
        .map(function(d){
            return {type: d.key, count: d.value};
        });

I end up getting true false values for the keys, but I want the keys to be 'Chiq' and 'Mont'.

Dataset:

[
    {
      "fruit": "banana",
      "type": "Chiq",
      "count": 1000
    },
    {
      "fruit": "banana",
      "type": "Mont",
      "count": 200
    },
    {
      "fruit": "watermelon",
      "type": "",
      "count": 100
    },
    {
      "fruit": "grape",
      "type": "",
      "count": 220
    }
  ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're mixing up the key method with filter:

var fruit_cnt = d3.nest()
        .key(function(d) { return d.type })
        .rollup(function(o){
            return d3.sum(o, function(d){
                return d.count;
            });
        })
        .entries(dataset.filter(function(d) { return d.fruit === "banana" }))
        .map(function(d){
            return {type: d.key, count: d.value};
        })
        
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!