how to generate heat maps given the points

2020-05-29 02:02发布

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.

标签: c# .net
8条回答
We Are One
2楼-- · 2020-05-29 02:35

A solution going from red to yellow to green

static Color CreateHeatColor(int value, decimal max)
    {
        if (max == 0) max = 1M;
        decimal pct = value/max;
         Color color = new Color();

        color.A = 255;

        if (pct < 0.34M)
        {
            color.R = (byte) (128 + (127 * Math.Min(3 * pct, 1M)));
            color.G = 0;
            color.B = 0;
        }
        else if (pct < 0.67M)
        {
            color.R = 255;
            color.G = (byte) (255 * Math.Min(3 * (pct - 0.333333M), 1M));
            color.B = 0;
        }
        else
        {
            color.R = (byte)(255 * Math.Min(3 * (1M - pct), 1M));
            color.G = 255;
            color.B = 0;
        }

        return color;
    }
查看更多
Melony?
3楼-- · 2020-05-29 02:39

This is a fix for Sam's code.

  public Color HeatMapColor(decimal value, decimal min, decimal max)
    {
        decimal val = (value - min) / (max - min);
        int r = Convert.ToByte(255 * val);
        int g = Convert.ToByte(255 * (1 - val));
        int b = 0;

        return Color.FromArgb(255,r,g,b);                                    
    }
查看更多
登录 后发表回答