Hello.
I am using heatmap to show some data. I was requested to add a TOTAL row and column on the chart, these sum the other cells values.
Problem is sum values are so much greater than data values that they make all data cells to look practically the same color.
Any way to overcome this? I was thinking on the ability to set max-min values for the gradient, and everything greater than gradient max value should look the same color.
Thank you.
|
<SfHeatMap DataSource="@dataSource">
<HeatMapEvents CellRendering="@CellRender"></HeatMapEvents>
<HeatMapTitleSettings Text="GDP Growth Rate for Major Economies (in Percentage)">
</HeatMapTitleSettings>
<HeatMapXAxis Labels="@xAxisLabels"></HeatMapXAxis>
<HeatMapYAxis Labels="@yAxisLabels"></HeatMapYAxis>
</SfHeatMap>
@code{
private void CellRender(HeatMapCellRenderEventArgs args)
{
if (args.CellValue > "2")
{
args.CellColor = "#EEEEEE";
}
}
double[,] dataSource = new double[2, 2]
{
{9, 2 },
{4, 1 }
};
string[] xAxisLabels = new string[] { "China", "India" };
string[] yAxisLabels = new string[] { "2008", "2009" };
} |
Hello. Thanks for your answer.
This answer has the potential to fix my issue, but it will require me to individually calculate and change every cell color, since the problem is not how dark the Total cell is, but how similar the other cells are.
Would it be possible on future releases to see a gradient-max and gradient-min implementation?
Would it be possible to see on a future release an integrated row-column sum implementation?
thank you again!
Hello Indhumathy Loganathan. Thanks for your answer.
I think you are not understanding the requirement.
The Idea would be to override the max value gradient gets from input data and uses for calculation with some user input value (say 150), so gradient is applied on those values and any bigger value than 150 gets stuck on a single color.
My solution for my particular case was the following. I hope it helps to understand what I wanted to achieve.
(its theoretical code since my licence is for 19.3 and this needs 19.4 to work)
protected void CellRender(HeatMapCellRenderEventArgs args)
{
if (args.XLabel=="Total" || args.YLabel=="Total") //a
{
args.CellColor = "#BABABA";
}
else //b
{
//c
var R = (int)176-176*args.Value/150.0;
var G = (int)232-(232-163)*args.Value/150.0;
var B = (int)176-(239-177)*args.Value/150.0;
//d
if (R<0) R=0;
if (G<163) G=163;
if (B<0) B=177;
//e
args.CellColor =$"#{R.ToString("X2")}{G.ToString("X2")}{B.ToString("X2")}";
}
//////////////////
// a: "Total" is the name of the bottom row and rightmost column. Those will be gray
// b: On any other column I'll manually calculate a fixed gradient.
// I know that my data will never be bigger than 150 for my particular case.
// c: Gradient Calculation.
// Lightest color should be (176,232,176) and darkest should be (0,163,177)
// d: Set color threshold. never darker than (0,163,177)
// e: assign the resulting hexadecimal color string to the cell
//////////////////
}
Just to clarify. My data will never be bigger than 150, except for the data on the totals row and column, that will be far bigger since those are special cells containing sums
|
<HeatMapPaletteSettings Type="@PalatteType">
<HeatMapPalettes>
<HeatMapPalette Value="4.3" Color="#FFFFDA"></HeatMapPalette>
<HeatMapPalette Value="7" Color="#EDF8B6"></HeatMapPalette>
<HeatMapPalette Value="9" Color="#CAE8B4"></HeatMapPalette>
<HeatMapPalette Value="15" Color="#78D1BD"></HeatMapPalette>
<HeatMapPalette Value="25" Color="#208FC6"></HeatMapPalette>
<HeatMapPalette Value="30" Color="#253494"></HeatMapPalette>
<HeatMapPalette Value="32" Color="#081D58"></HeatMapPalette>
</HeatMapPalettes>
</HeatMapPaletteSettings> |
|
<HeatMapPaletteSettings Type="@PalatteType">
<HeatMapPalettes>
<HeatMapPalette StartValue="0" EndValue="10" MinColor="#F0C27B" MaxColor="#BE8D6C"></HeatMapPalette>
<HeatMapPalette StartValue="10" EndValue="30" MinColor="#A26E63" MaxColor="#4B1248"></HeatMapPalette>
<HeatMapPalette StartValue="30" EndValue="55" MinColor="#694b77" MaxColor="#d27d85"></HeatMapPalette>
<HeatMapPalette StartValue="55" EndValue="99" MinColor="#ed9485" MaxColor="#e44841"></HeatMapPalette>
</HeatMapPalettes>
</HeatMapPaletteSettings>
|