how to generate heat maps given the points

前端 未结 8 1700
猫巷女王i
猫巷女王i 2021-02-06 07:59

I want to generate a heat map in windows form. I have a set of points as the input. How to go about doing this in the simplest way? Thanks.

8条回答
  •  死守一世寂寞
    2021-02-06 08:35

    If you want red to green via yellow, you could also use HSL to get your heatmap. The numbers in that instance would be 0 - 60, where 0 = red and 60 = green (see figure 11 on this link).

    To implement, you need to use System.Runtime.InteropServices and add the following:

    [DllImport("shlwapi.dll")]
    public static extern int ColorHLSToRGB(int H, int L, int S);
    

    In the method, val is a long value and m_iMax is the largest number in the collection, you could change it as required:

    if (val == 0)
        return ColorTranslator.ToHtml(Color.FromArgb(255, 255, 255)); // white
    else
    {
      // 0 = red, 60 = green
      int col = 60 - (int)(60 * val / m_iMax);
    
      return ColorTranslator.ToHtml(ColorTranslator.FromWin32(ColorHLSToRGB(col, 120, 240)));
    }
    

    The following is the result of the code above in a HTML table:

提交回复
热议问题