I'm trying to create something a little like a quantize scale, but act like a linear color scale?
When I try to put multiple colors into a linear scale, it seems to only scale between the first two colors.
I'd like multiple colors like a quantize scale, but fade between those colors. I'm unsure if this is possible.
//red and green works ok var color = d3.scale.linear() .range(['red','green']); //doesn't work - only red and green show var color = d3.scale.linear() .range(['red','green', 'blue']); //red green and blue show, however it doesn't fade between the colors var color = d3.scale.quantize() .range(['red','green', 'blue']);
An array of eight categorical colors represented as RGB hexadecimal strings. An array of eight categorical colors represented as RGB hexadecimal strings.
The d3. scaleLinear() method is used to create a visual scale point. This method is used to transform data values into visual variables.
A scale's range, on the other hand, describes the set of possible output values that the input values can be converted to. If we're building a bar chart to display our test scores, we'd want our range to describe the minimum and maximum bar sizes.
scaleBand() function in D3. js is used to construct a new band scale with the domain specified as an array of values and the range as the minimum and maximum extents of the bands. This function splits the range into n bands where n is the number of values in the domain array.
You have to use domain 'pivot' value like:
d3.scale.linear() .domain([0, pivot, max]) .range(['red', 'green', 'blue']);
From the documentation for continuous scale domains:
Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale. For example, to create a diverging color scale that interpolates between white and red for negative values, and white and green for positive values, say:
var color = d3.scaleLinear() .domain([-1, 0, 1]) .range(["red", "white", "green"]); color(-0.5); // "rgb(255, 128, 128)" color(+0.5); // "rgb(128, 192, 128)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With