Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculating heat map colours
    primarykey
    data
    text
    <p>I'm working on a heat map made up of an HTML table. This table contains <em>n</em> cells and has a <em>lowest</em> value and a <em>highest</em> value (highest is always higher than lowest). Each cell has a <em>cell</em> value. All these values are ints.</p> <p>Cells with the lowest value are meant to be a light blue, scaling across to the point where the cells with the highest value are a deep red. See gradient below for an ideal range:</p> <p><img src="https://i.stack.imgur.com/9Ve6P.png" alt="enter image description here"></p> <p>To calculate the hex colour value of each individual cell, I look at the <em>lowest</em> and <em>highest</em> values from the table and the cell's <em>total</em> value, passing them into a method that returns the RGB hex, ready to be used with HTML's <em>background-color</em> style.</p> <p>Here is the method so far:</p> <pre><code>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; } </code></pre> <p>With a <em>lowest</em> value of 0 and a <em>highest</em> value of 235, this method returns the following table (cell values are in the cells).</p> <p><img src="https://i.stack.imgur.com/cFKrv.png" alt="enter image description here"></p> <p>Example case: If <em>lowest</em> was 20, <em>highest</em> was 400 and <em>cell</em> was 60, I would want the method returning the RGB hex of the colour about 15.8% of the way along the gradient.</p> <pre><code>400 - 20 = 380 380 / 60 = 6.33 100 / 6.33 = 15.8 </code></pre> <p>I'm aware that this formula isn't quite accurate but that's partially why I'm asking for help here.</p> <p>I've made it this far but I'm really not sure how to proceed. Any help is hugely appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload