Skip to content

Instantly share code, notes, and snippets.

@jueyang
Last active August 29, 2015 14:02
Show Gist options
  • Save jueyang/44e289553ab14c9726db to your computer and use it in GitHub Desktop.
Save jueyang/44e289553ab14c9726db to your computer and use it in GitHub Desktop.
Gist from mistakes.io: explaining different d3.scale()
"hello, world"; // edit this to begin
require('http://d3js.org/d3.v3.min.js');
// equal interval
var color1 = d3.scale.quantize()
.domain([0,10]) // continuous
.range(["#000", "#111", "#222", "#333", "#444", "#555"]);
// manual interval
var color2 = d3.scale.threshold()
.domain([0,2,4,6,8,10]) // discrete, starts from -1 and ends at (i-1)
.range(["#000", "#111", "#222", "#333", "#444", "#555"]);
// sequtial
var color3 = d3.scale.linear()
.domain([0,10]) // continuous (start--->end)
.range(["#000", "#111"]); // gradient between #000 and #111 (start--->end)
color1(10);
color2(10);
color3(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment