Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

304
Visualizações
How to show multiple values in d3 sunburst chart?

I am trying a sunburst chart using d3(V4) & Vue2 to show the values of Sales, Salience, Goly% in a single chart.

working pen.

here is my JSON

{
    name: "root",
    children: [{
        name: "product1",
        children: [{
            name: "zone1",
            size: 45632,
            salience: 200,
            goly: 10,
        }, {
            name: "zone2",
            size: 986413,
            salience: 100,
            goly: 20,
        }, ],
    }, {
        name: "product2",
        children: [{
            name: "zone1",
            size: 54752,
            salience: 250,
            goly: 15,
        }, {
            name: "zone2",
            size: 973542,
            salience: 170,
            goly: 18,
        }, ],
    }, {
        name: "product3",
        children: [{
            name: "zone1",
            size: 671378,
            salience: 378,
            goly: 35,
        }, {
            name: "zone2",
            size: 12345,
            salience: 615,
            goly: 26,
        }, ],
    }, ]
};

size in above json denotes sales value.

i tried using eachBefore as mentioned here

root["salience"] = 1;
root.eachBefore(d => {
    if (d.parent) {
        let parent_salience = d.parent.salience;
        if (parent_salience === NaN) parent_salience = 0;
        d.salience = d.data.salience + parent_salience;
    };
});

but it didn't work either.

i even tried to alter the source code of sum function

Node.prototype = hierarchy.prototype = {
    constructor: Node,
    count: node_count,
    each: node_each,
    eachAfter: node_eachAfter,
    eachBefore: node_eachBefore,
    sum: node_sum,
    sum2: node_sum2, /* altered here */
    sort: node_sort,
    path: node_path,
    ancestors: node_ancestors,
    descendants: node_descendants,
    leaves: node_leaves,
    links: node_links,
    copy: node_copy
};

function node_sum2(value) {
    return this.eachAfter(function(node) {
        var obj = value(node.data);
        var sum = +obj.sales || 0,
            salience = +obj.salience || 0,
            goly = +obj.goly || 0,
            children = node.children,
            _children = node.data.children,
            i = children && children.length;

        while (--i >= 0) {
            sum += children[i].value;
            salience += children[i].salience;
            goly += children[i].goly;
        }

        node.value = sum;
        node.salience = salience;
        node.goly = goly;
    });
}

but i get the same result even if i use d3.sum2() instead of d3.sum

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda