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

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

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 Denunciar

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 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