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

110
Views
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 answers
Answer question

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 Report

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