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

112
Visualizações
D3 Sankey customization

Most libraries provide limited customization of the Sankey chart (like node color, width, padding).

Default Sankey chart (d3):

enter image description here

But what if I need to change node heights and center the nodes vertically? How I can do that?

My requirements:

enter image description here

Can anyone help me?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Without watching your code - it is a guessing game. So, I assume, you've used examples of sankey D3.js in the internet that are pretty much sharing same code. At some point you could see something like this:

var sankey = d3.sankey()
    .nodeWidth(12)
    .nodePadding(12)
    .size([width, height]);

Please, try to fiddle around with nodeWidth (enlarge the value) to get what you're after.

about 4 years ago · Juan Pablo Isaza Relatório

0

Slightly hacky, but you could override the CSS rules to style the elements however you wish.

For example, if I have a d3-generated Sankey chart within a div named "sankey", I can add these CSS rules to change the rect elements to red, and the path elements that form the links to blue.

From some very brief testing, the rect elements seem to require the "!important" CSS modifier, hence the comment about it seeming a little hacky:

#sankey > svg > g > g > g > rect {
    fill: red !important;
}

#sankey > svg > g > g > path {
    stroke: blue;
    stroke-opacity: 0.7;
}

To make the rects larger, you could possibly set their stroke color to be the same as the fill, and set the stroke width to something large, and then play with the "nodePadding" parameter in the d3 API.

I've attached a screenshot of what I got to work by playing with these:

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
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