d3 / d3-scale

Encodings that map abstract data to visual representation.
https://d3js.org/d3-scale
ISC License
1.59k stars 286 forks source link

get HEX color #259

Closed beocaca closed 2 years ago

beocaca commented 2 years ago

hello, i need to get the hex color example document :

var color = d3.scaleLinear()
    .domain([10, 100])
    .range(["brown", "steelblue"]);

color(20); // "#9a3439"
color(50); // "#7b5167"

but i get the rgba color

color(20); // "rgb(154, 52, 57)"
color(50); // "rgb(123, 81, 103)"
mbostock commented 2 years ago

You can use d3.rgb("rgb(154, 52, 57)").formatHex(). You can also write your own interpolate that generates hexadecimal strings with the scale if you prefer.