d3 / d3-scale-chromatic

Sequential, diverging and categorical color scales.
https://d3js.org/d3-scale-chromatic
Other
798 stars 107 forks source link

chromatic scales not working properly? #3

Closed jk2227 closed 8 years ago

jk2227 commented 8 years ago

Trying to follow the example here, if I do the following

var yellow = d3.interpolateYlGn(0), // "rgb(255, 255, 229)"

var yellowGreen = d3.interpolateYlGn(0.5), // "rgb(120, 197, 120)"

var green = d3.interpolateYlGn(1); // "rgb(0, 69, 41)"

then I get the following values

yellow -> "#ffffe5"

yellowGreen -> "#77.aaaaaaaaaaacc5.55555555555877.d55555555554"

green -> "#004529"

The first and the third output makes sense but I cannot figure out what to do with the second output; does anyone have any pointers on this?

mbostock commented 8 years ago

You appear to be using D3 3.x. You need to use D3 4.0 or higher, e.g.,

<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.js"></script>

Equivalently you can use d3-color and d3-interpolate 1.0:

<script src="https://d3js.org/d3-color.v1.js"></script>
<script src="https://d3js.org/d3-interpolate.v1.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.js"></script>