I want to create a dynamic dashboard where the user can add panels. A lot of these panels contain Syncfusion components. Eg. SfHeatMap.
In order to scale the SfHeatMap component properly inside the panel, I need to assign an ID. Of course the dashboard can contain multiple panels, each with an SfHeatMap, so in that case, the ID needs to be generated randomly so no 2 SfHeatMap components have the same ID. If I do that, on some panels the SfHeatMap is rendered, on others it is missing. Below you van find the code of a heatmap widget. This widget is than added to the panel.
'''
@using Syncfusion.Blazor.CircularGauge;
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.HeatMap
<div style="height:100%; width:100%">
<SfHeatMap ID="@id" AllowSelection="true" @ref="heatMap" Width="100%" DataSource="@HeatMapData">
<HeatMapEvents CellSelected="CellSelect"></HeatMapEvents>
<HeatMapCellSettings ShowLabel="false" TileType="CellType.Rect"></HeatMapCellSettings>
<HeatMapXAxis Labels="@XAxisLabels" ValueType="Syncfusion.Blazor.HeatMap.ValueType.Category"></HeatMapXAxis>
<HeatMapYAxis Labels="@YAxisLabels" ValueType="Syncfusion.Blazor.HeatMap.ValueType.Category"></HeatMapYAxis>
<HeatMapPaletteSettings Type="PaletteType.Fixed">
<HeatMapPalettes>
<HeatMapPalette Color="#FF0000" Label="Low" Value=0.5></HeatMapPalette>
<HeatMapPalette Color="#FF6500" Label="Moderate" Value=0.8></HeatMapPalette>
<HeatMapPalette Color="#32CD32" Label="High" Value=1></HeatMapPalette>
</HeatMapPalettes>
</HeatMapPaletteSettings>
</SfHeatMap>
</div>
<style>
#chart {
width: inherit;
height: inherit;
}
[ID$="chart"] {
width: inherit;
height: inherit;
}
</style>
@code {
[Parameter]
public HeatmapWidgetData WidgetData { get; set; }
[Parameter]
public EventCallback<CurrentValueWidgetData> OpenSettings { get; set; }
private SfHeatMap heatMap;
private string id = Guid.NewGuid().ToString() + "-chart";
double?[,] GetDefaultData()
{
double?[,] dataSource = new double?[,]
{
{0.3, 0.8, 1.1},
{0.4, null, 1.05},
{1.2, 0.9, 0.6}
};
return dataSource;
}
string[] XAxisLabels = new string[] { "Room 1", "Room 2", "Room 3" };
string[] YAxisLabels = new string[] { "Line 3", "Line 2", "Line 1" };
public object HeatMapData { get; set; }
protected override void OnInitialized()
{
HeatMapData = GetDefaultData();
}
private void CellSelect(ISelectedEventArgs args)
{
Console.WriteLine(args.Data);
}
}
'''