I'm letting users select one of four numerical series from a dropdown to drive the colouring of circles in a bubble chart. (There are similar dropdowns for radius, x and y.)
d3.select("select#colour").on('change',function(d) {
var tempIndex = this.selectedIndex;
yearlyBubbleChart.colorAccessor(function (p) {
return p.value[optionArray[0][tempIndex]];
});
yearlyBubbleChart.colors(colorbrewer[optionArray[7][tempIndex]][optionArray[8][tempIndex]]);
yearlyBubbleChart.colorDomain([optionArray[5][tempIndex][0], optionArray[5][tempIndex][1]]);
});
To do this, I'm using colorAccessor, colors and colorDomain, in that order. (I've noticed in some cases that the order of these three matters.) I'd like users to be able to select min and max colours, and drive the colouring from that. For this I need to colour the bubbles from just two colours, e.g. ['white','blue']. Higher numeric values would be proportionately more blue.
It seems a really easy thing to do but I can't work it out. Supplying an array of two colours is generally used to alternate, and in a bubble chart the minimum bubble is white and the rest are blue. How do I get a continuous colour range by inputting just two colours?
Thanks
d3 knows how to interpolate between colors. You can create a linear scale where the range (output values) are colors.
Below is an example which shows various colors generated by the scale at set percentages (where 0% is all white and 100% is all blue).