It only resizes when i resize the whole browser window. But how to solve this issue with code?
The solution how it looks is shown in a demo video for rezising on the syncfusion website but the solutions can not be found in the synfusion documentation.
Hi Moritz,
We have reviewed your query and understand that you want to resize the Accumulation Chart along with the panel resize in the Dashboard Layout component. To achieve this, we suggest binding the “Resizing” event and calling the AccumulationChart component’s “Refresh” method within the event handler. This implementation ensures that the Accumulation Chart adapts properly inside the panel when resizing.
Refer to the below code snippet for further reference.
|
[Index.razor]
<div class="content"> <SfDashboardLayout Columns="6" CellSpacing="@(new double[]{10 ,10 })" AllowResizing=true> <DashboardLayoutPanels> <DashboardLayoutPanel Id="Panel4" SizeX=3 SizeY=2 Row=2 Column=0> <HeaderTemplate><div class='header'> Sales Comparison in Products </div></HeaderTemplate> <ContentTemplate> <div style="height:100%; width:100%;"> <SfAccumulationChart @ref="accumulationChart" Title="Mobile Browser Statistics" Height="100%" Width="100%"> <AccumulationChartSeriesCollection> <AccumulationChartSeries DataSource="@StatisticsDetails" XName="Browser" YName="Users" Name="Browser"> </AccumulationChartSeries> </AccumulationChartSeriesCollection>
<AccumulationChartLegendSettings Visible="true"></AccumulationChartLegendSettings> </SfAccumulationChart> </div> </ContentTemplate> </DashboardLayoutPanel> </DashboardLayoutPanels> <DashboardLayoutEvents Resizing="OnResize"></DashboardLayoutEvents> </SfDashboardLayout> </div> @code {
SfAccumulationChart accumulationChart;
...... public void OnResize() { this.accumulationChart.Refresh(); } }
|
We have also attached a solution sample for your reference.
Sample : Attached as zip folder.
Regards,
Suresh.
I need something different because the chart is added dynamically so i cant directly address it.
Hi Moritz,
We have reviewed your query and understand that you are dynamically updating the Accumulation chart component within the ContentTemplate property of the Dashboard Layout component. To ensure the Accumulation chart fits properly inside the panel after a dynamic update, we recommend calling the Accumulation chart component’s “refresh” method. This should resolve the fitting issue you are experiencing.
If the issue persists after following this suggestion, we suggest you to share the below requested details with us.
These details will help us to validate the query further and provide you with a prompt solution.
Regards,
Suresh.
This is my complete code for better understanding the problem:
This is my PageIndex.razor:
@page "/"
@using System.Text.Json
@inherits ComponentBaseView<ViewModelIndex>
@using Syncfusion.Blazor.Grids
<div @attributes="Attributes">
<ControlScroller>
<ControlContent Heading="Dashboard">
<SfButton @onclick='(() => AddPanel(PanelName))' Content="AddPanel"></SfButton>
<SfButton @onclick='(() => AddPanel(PieName))' Content="Add Piechart"></SfButton>
<SfButton @onclick='(() => AddPanel(LineName))' Content="Add Linechart"></SfButton>
<SfDashboardLayout Columns="3" CellSpacing="@(new double[]{10 ,10 })" CellAspectRatio="2" @ref="dashboard" AllowResizing="true">
<DashboardLayoutPanels>
<DashboardLayoutPanel Column="0" Row="0" SizeX="2">
<HeaderTemplate>
<div>Chart</div>
</HeaderTemplate>
<ContentTemplate>
<SfChart Title="Beispielchart">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartData" XName="Category" YName="Value" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Line"></ChartSeries>
</ChartSeriesCollection>
</SfChart>
</ContentTemplate>
</DashboardLayoutPanel>
</DashboardLayoutPanels>
</SfDashboardLayout>
<SfButton OnClick="DashboardSerialize">Serialize</SfButton>
<SfButton OnClick="DashboardDeserialize">Deserialize</SfButton>
<p>@panelSerialize</p>
</ControlContent>
</ControlScroller>
</div>
@code {
/// <summary>
/// Fügt ein neues Panel hinzu.
/// </summary>
/// <param name="name">Der Name des neuen Panels.</param>
public async Task AddPanel(string name)
{
string panelId = name + "_" + idCount;
await this.dashboard.AddPanelAsync(new PanelModel
{
Id = panelId,
Row = AmountRows - 1,
Column = amountColumns - 1,
MinSizeX = 1,
MaxSizeX = 2,
MinSizeY = 1,
MaxSizeY = 2,
Content = GetContent(name),
Header = GetHeader(panelId, name)
});
idCount++;
await this.dashboard.RefreshAsync();
}
protected RenderFragment GetContent(string name)
{
switch (name)
{
case PanelName:
return @<div class="full-size">@name</div>;
case LineName:
return @<div class="full-size">
<SfChart Title="Beispielchart">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartData" XName="Category" YName="Value" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Line"></ChartSeries>
</ChartSeriesCollection>
</SfChart>
</div>;
case PieName:
return @<div class="full-size">
<SfAccumulationChart Title="Example Statistics">
<AccumulationChartSeriesCollection>
<AccumulationChartSeries DataSource="@ChartData" XName="Category" YName="Value" Name="Category" InnerRadius="40%"></AccumulationChartSeries>
</AccumulationChartSeriesCollection>
<AccumulationChartLegendSettings Visible="true"></AccumulationChartLegendSettings>
</SfAccumulationChart>
</div>
;
default:
return @<div class="full-size">@name</div>;
}
}
protected RenderFragment GetHeader(string id, string name)
{
return @<div>
<span>@name</span>
<button class="deleteBTN" @onclick="(() => RemovePanel(id))">Delete</button>
</div>;
}
/// <summary>
/// Deserialisiert das Dashboard.
/// </summary>
public async Task DashboardDeserialize()
{
await dashboard.RemoveAllAsync();
var panels = JsonSerializer.Deserialize<List<PanelModel>>(standardDashboard);
if (panels != null)
{
foreach (var panel in panels)
{
string name = panel.Id.Split('_').First();
string panelId = name + "_" + idCount;
await this.dashboard.AddPanelAsync(new PanelModel
{
Id = panelId,
Row = panel.Row,
Column = panel.Column,
SizeX = panel.SizeX,
SizeY = panel.SizeY,
Content = GetContent(name),
Header = GetHeader(panelId, name)
});
idCount++;
}
}
await this.dashboard.RefreshAsync();
}
}
This is my PageIndex.razor.cs:
protected List<ChartDataModel> ChartData { get; set; } = new List<ChartDataModel>();
/// <summary>
/// Datenmodell für Chart-Daten.
/// </summary>
protected class ChartDataModel
{
/// <summary>
/// Kategorie der Daten.
/// </summary>
public string Category { get; set; } = string.Empty;
/// <summary>
/// Wert der Daten.
/// </summary>
public double Value { get; set; }
}
/// <inheritdoc/>
protected override void OnInitialized()
{
ViewModel = new ViewModelIndex();
base.OnInitialized();
ChartData = new List<ChartDataModel>
{
new ChartDataModel { Category = "Jan", Value = 15 },
new ChartDataModel { Category = "Feb", Value = 20 },
new ChartDataModel { Category = "Mär", Value = 25 },
new ChartDataModel { Category = "Apr", Value = 30 },
new ChartDataModel { Category = "Mai", Value = 0 },
new ChartDataModel { Category = "Jun", Value = 24 },
new ChartDataModel { Category = "Jul", Value = 28 },
new ChartDataModel { Category = "Aug", Value = 60 },
new ChartDataModel { Category = "Sep", Value = 19 },
new ChartDataModel { Category = "Okt", Value = 14 },
new ChartDataModel { Category = "Nov", Value = 40 },
new ChartDataModel { Category = "Dez", Value = 10 }
};
}
private const string PanelName = "Panel";
private const string PieName = "Donutdiagramm";
private const string LineName = "Liniendiagramm";
private const int AmountRows = 2;
private const int amountColumns = 3;
SfDashboardLayout dashboard;
string panelSerialize;
private static int idCount = 0;
string standardDashboard = "[{\"AllowDragging\":true,\"Column\":2,\"CssClass\":null,\"Enabled\":true,\"Id\":\"panel_0\",\"MaxSizeX\":2,\"MaxSizeY\":2,\"MinSizeX\":1,\"MinSizeY\":1,\"Row\":0,\"SizeX\":1,\"SizeY\":1,\"ZIndex\":1000},{\"AllowDragging\":true,\"Column\":1,\"CssClass\":null,\"Enabled\":true,\"Id\":\"pie_1\",\"MaxSizeX\":2,\"MaxSizeY\":2,\"MinSizeX\":1,\"MinSizeY\":1,\"Row\":0,\"SizeX\":1,\"SizeY\":1,\"ZIndex\":1000},{\"AllowDragging\":true,\"Column\":0,\"CssClass\":null,\"Enabled\":true,\"Id\":\"line_2\",\"MaxSizeX\":2,\"MaxSizeY\":2,\"MinSizeX\":1,\"MinSizeY\":1,\"Row\":0,\"SizeX\":1,\"SizeY\":1,\"ZIndex\":1000}, {\"AllowDragging\":true,\"Column\":2,\"CssClass\":null,\"Enabled\":true,\"Id\":\"menu_0\",\"MaxSizeX\":2,\"MaxSizeY\":2,\"MinSizeX\":1,\"MinSizeY\":1,\"Row\":0,\"SizeX\":1,\"SizeY\":1,\"ZIndex\":1000}]";
/// <summary>
/// Serialisiert das Dashboard.
/// </summary>
protected async void DashboardSerialize()
{
panelSerialize = string.Empty;
panelSerialize = JsonSerializer.Serialize(await dashboard.Serialize());
}
/// <summary>
/// Entfernt ein Panel.
/// </summary>
/// <param name="panelId">Die ID des zu entfernenden Panels.</param>
protected async Task RemovePanel(string panelId)
{
await dashboard.RemovePanelAsync(panelId);
await this.dashboard.RefreshAsync();
}
Your solution does not seem to work for my code. Please update us if there is an posibility to solve this issue.
Hi Moritz,
We have reviewed your query and understand that you are experiencing an issue with the Accumulation Chart not fitting properly within the Dashboard Layout panel when added dynamically. To resolve this, we recommend setting the height and width properties to 100% for the div element that wraps the Accumulation Chart component. This adjustment will ensure that the chart fits perfectly inside the panel.
Refer to the below code snippet for further reference.
|
[Index.razor]
<div class="content"> <div style="padding-right:10px;padding-bottom:10px;text-align: right;"> <SfButton CssClass="e-btn e-primary" Content="Add Panel" @onclick="AddClick"></SfButton> </div> ...... </div> @code { SfDashboardLayout dashboardObject; public int Count = 9; public async Task AddClick(EventArgs args) { string ContentValue = this.Count.ToString(); PanelModel panel = new PanelModel { Id = this.Count.ToString() + "_layout", SizeX = 1, SizeY = 1, Column = 1, Row = 2, Content = GetContent(), Header = GetHeader() }; await dashboardObject.AddPanelAsync(panel); this.Count = this.Count + 1; }
protected RenderFragment GetContent() { return @<div class="full-size" style="height:100%; width:100%;"> <SfAccumulationChart Title="Example Statistics"> .... </SfAccumulationChart> </div>; } ......
|
We have also attached a solution sample for your reference.
Sample : Attached as zip folder.
Regards,
Suresh.
We request you to re-render the chart using RefreshAsync method in OnResizeStop event. We have attached the modified sample for your reference. Please check with below code snippet and GIF.
<SfDashboardLayout> <DashboardLayoutEvents OnResizeStop="ResizeStop"></DashboardLayoutEvents> <DashboardLayoutPanels> <DashboardLayoutPanel Column="0" Row="0" SizeX="2"> <ContentTemplate> <SfChart @ref="chart1"></SfChart> </ContentTemplate> </DashboardLayoutPanel> </DashboardLayoutPanels> </SfDashboardLayout> SfChart chart1; public void ResizeStop(Syncfusion.Blazor.Layouts.ResizeArgs args) { if (chartObjects.TryGetValue(args.Id, out var chartObject)) { chartObjects[args.Id].RefreshAsync(true); } if(pieObjects.TryGetValue(args.Id, out var pieObject)) { pieObjects[args.Id].Refresh(true); }
} protected override void OnAfterRender(bool firstRender) { chartObjects["layout_0"] = chart1;// for initially rendered chart. } public Dictionary<string, SfChart> chartObjects = new Dictionary<string, SfChart>(); public Dictionary<string, SfAccumulationChart> pieObjects = new Dictionary<string, SfAccumulationChart>(); protected RenderFragment GetContent(string id, string name) { switch (name) { case LineName: return @<div style="height:100%; width:100%;" class="full-size"> <SfChart @ref=chartObjects[id]></SfChart> </div>; case PieName: return @<div style="height:100%; width:100%;" class="full-size"> <SfAccumulationChart @ref="pieObjects[id]"></SfAccumulationChart> </div>; } } |
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/AddChart-1202685841.zip
Please let us know if you have any concerns.
Hi Moritz,
We have reviewed your query regarding the inclusion of the Chart component refresh method in the Dashboard Layout component. We would like to inform you that the Dashboard Layout is designed as a layout component, allowing the integration of various components using Template support. Due to this design structure, it is not possible to specifically include the Chart component refresh method. This is the current behavior of the Dashboard Layout component.
Regards,
Suresh.