javascript - d3: Color Range with an array with more than 2 colors -


i'm trying shade layer in map (using mapbox) depending on value of properties in .json file. code works 2 color values passed through. snippet of color coding below.

  var color =     d3.scale.linear()     .domain(range)     .range([#f0f0d0', '#228b22]); 

it fail if this

  var color =     d3.scale.linear()     .domain(range)     .range(['930f16', '#f0f0d0', '#228b22]); 

the map display range of first 2 colors.

how extend if wanted range of colors beyond two? instance, if wanted lower end red, middle quantiles white, , top quantiles green?

something this?

var color = d3.scale.linear()     .domain([-1, 0, 1])     .range(['#930f16', '#f0f0d0', '#228b22']); 

this interpolate between '#f0f0d0' , '#930f16' negative values, , '#f0f0d0' , '#228b22' positive values.

hope helps!


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -