how to generate heat maps given the points

前端 未结 8 1701
猫巷女王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:47

    Here is a simple method that will generate a color based on the relative position of a value between min and max. Values closer to min will be greener, while values closer to max will be redder.
    To use this method, generate your list of values and calculate the min and max values. If you are building a grid you can handle the RowDataBound event or something similar and call the HeatMap method from there. Get a reference to the cell and set the background color to the color returned by the HeatMap method.

    public Color HeatMap(decimal value, decimal min, decimal max)
    {
       decimal val = (value - min) / (max-min);
       return new Color
       {
           A = 255,
           R = Convert.ToByte(255 * val),
           G = Convert.ToByte(255 * (1-val)),
           B = 0
       };
    }
    

提交回复
热议问题