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.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
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.
Building on the answers already here, this method allows you to specify the
Colors
you wish to use as the max and min colours.The results look like this for a test
DataGrid
with some sample data.This worked well for me.
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:
In the method, val is a long value and m_iMax is the largest number in the collection, you could change it as required:
The following is the result of the code above in a HTML table:
The C# version of "Curtis White"'s answer:
Divide the surface up into a grid of cells, and count the points inside each cell.
Given the count of points, calculate a color for each cell