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

173
Views
D3.js generate a color proportional to the values of a key

I have a Tree data structure where each non-leaf node (children) have this object:

    mime_types={
  "application/octet-stream": 1,
  "application/x-executable": 49,
  "application/x-object": 13,
  "application/x-sharedlib": 47,
  "image/gif": 5,
  "image/png": 3,
  "inode/symlink": 4,
  "text/plain": 58
}

Each leaf of my tree have a single type and its relative color (for example, a text/plain leaf will be colored blue). I implemented it doing:

var ListMimes = ['text/plain', 'application/x-executable', 'application/x-sharedlib', 'application/x-object', 'image/gif', 'inode/symlink', 'image/png', 'application/octet-stream']

var myColor = d3.scaleOrdinal().domain(ListMimes).range(d3.schemeSet3);

But for each non-leaf node, i want to color it (i'm drawing a sunburst) in a "proportional" way. I try to explain better: In this example i have text/plain with value 58, so this will "weight" much more than application/octet-stream in the result of the final color. So if text/plain is blue, and application/octet-stream is green, the final color will be blue with a very very little quantity of green

How can i do it using d3?

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