We have a heatmap we want to display. The numbers that will make up the values being displayed are unknown (except that they will be positive integers). The range of numbers
This answer is probably a little late to the party. I'm displaying some environmental data, and need to colour the resulting bars from green to red relative to the max and min of the data set (or which ever values are passed as max and min to the function. Anyway, the below accomplishes that. Can be changed for blue to red fairly easily enough, I would think.
// scale colour temp relatively
function getColourTemp(maxVal, minVal, actual) {
var midVal = (maxVal - minVal)/2;
var intR;
var intG;
var intB = Math.round(0);
if (actual >= midVal){
intR = 255;
intG = Math.round(255 * ((maxVal - actual) / (maxVal - midVal)));
}
else{
intG = 255;
intR = Math.round(255 * ((actual - minVal) / (midVal - minVal)));
}
return to_rgb(intR, intG, intB);
}