Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda