d3 / d3-scale

Encodings that map abstract data to visual representation.

Home Page:https://d3js.org/d3-scale

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get HEX color

beocaca opened this issue · comments

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

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.