Create a dynamic d3 color scale between two color values

I have a d3 pie chart with color function:

var color = d3.scale.ordinal() .range(['#0075B4', '#70B5DC']); 

If there are only two values ​​/ pieces, this works. But if there are more, I want to choose colors between two data.

d3 pie chart

Above, with three pieces of cake, a piece labeled β€œCost 3” will have a color that is between #0075B4 and #70B5DC .

Is this possible with d3? Here is the jsfiddle of what I have so far: http://jsfiddle.net/9ruzntrr/1/

+6
source share
1 answer

Yes, just use colors on a linear scale:

 var color = d3.scale.linear().domain([costMin,costMax]) .range(['#0075B4', '#70B5DC']); 
+5
source

Source: https://habr.com/ru/post/979960/


All Articles