I am using several different charts inside of the Dashboard Layout control. It seems that in order for the chart to automatically resize when the browser is resized, I need to set three things:
#1 - There should be a div in the ContentTemplate of the DashboardLayoutPanel with a height and width of 100%.
#2 - The chart control itself needs to have a height and width of 100%.
#3 - An HtmlAttributes needs to be defined that points to a dictionary that points to a style with height and width of 100% like this:
Dictionary<string, object> ChartAttribute = new Dictionary<string, object>()
{
{ "class", "custom-chart" }
};
.custom-chart {
width: 100%;
height: 100%;
}
I can inspect the HTML/CSS in the browser and see this class applied. The chart will resize automatically as you resize the browser.
But if you want to change the data that is displayed in the chart by nulling out the datasource and recreating it, when the chart is rendered again it loses this class definition and the height changes to 450 pixels. If I manually add the class back by inspecting the HTML/CSS elements and adding back custom-chart, once I resize the browser, the chart automatically resizes to the correct container size.
This seems to happen on at least line and area charts. Here is one of my examples:
<SfChart Title="Disposition Count by Call Date"
HtmlAttributes="ChartAttribute"
@ref="DispositionByDateChart"
UseGroupingSeparator="true"
EnableAnimation="true"
Height="100%"
Width="100%">
<ChartEvents Loaded="ChartLoad" Resized="ChartResized" />
<ChartArea>
<ChartAreaBorder Width="0" />
</ChartArea>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime"
Skeleton="Ed">
<ChartAxisMajorGridLines Width="0" />
</ChartPrimaryXAxis>
<ChartPrimaryYAxis LabelFormat="{value} Calls">
<ChartAxisLineStyle Width="0" />
<ChartAxisMajorTickLines Width="0" />
</ChartPrimaryYAxis>
<ChartTooltipSettings Enable="true"
Format="${point.x} : ${point.y}" />
<ChartSeriesCollection>
<ChartSeries DataSource="@VM.DispositionByDaysChartDataSource"
Name="Calls"
XName="x"
Width="2"
Opacity="1"
YName="y"
Type="ChartSeriesType.MultiColoredLine">
<ChartMarker Visible="true"
Width="10"
Height="10">
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
<ChartLegendSettings Visible="false" />
</SfChart>