c# - Calculating heat map colours -


i'm working on heat map made of html table. table contains n cells , has lowest value , highest value (highest higher lowest). each cell has cell value. these values ints.

cells lowest value meant light blue, scaling across point cells highest value deep red. see gradient below ideal range:

enter image description here

to calculate hex colour value of each individual cell, @ lowest , highest values table , cell's total value, passing them method returns rgb hex, ready used html's background-color style.

here method far:

public string converttotaltorgb(int low, int high, int cell) {     int range = high - low;      int main = 255 * cell/ range;     string hexr = main.tostring("x2");     int flip = 255 * (1 - (cell/ range));     string hexb = flip.tostring("x2");      return hexr + "00" + hexb; } 

with lowest value of 0 , highest value of 235, method returns following table (cell values in cells).

enter image description here

example case: if lowest 20, highest 400 , cell 60, want method returning rgb hex of colour 15.8% of way along gradient.

400 - 20 = 380 380 / 60 = 6.33 100 / 6.33 = 15.8 

i'm aware formula isn't quite accurate that's partially why i'm asking here.

i've made far i'm not sure how proceed. hugely appreciated!

what want hsv color, because hue (h value) cyclical. if hue between 0 , 1, indicates how far along color gradient want be. saturation , value components 1 in case.

follow hsv rgb conversion code here: hsv rgb stops @ yellow c#

public string converttotaltorgb(int low, int high, int cell) {     int range = high - low;     float h= cell/ (float)range;     rgb = hsvtorgb(h,1.0f,1.0f);     return "#" + rgb.r.tostring("x2") + rgb.g.tostring("x2") + rgb.b.tostring("x2"); } 

if know can target browsers support (css3), can render hsv value directly.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -