Chart not rendering in dialog

Hello, my chart doesn't render in blazor WASM.

This is the flow of the application SF Grid->button click on row>Opens Modal passing the datasource as a parameter->When model opens, its contents display the chart

I have a SF Grid component in Index.razor, when a button gets clicked on the grid, it will take the rows data and trigger the LoadValueHistory method in Index.cs. The LoadValueHistory passes the Datasource list to the Modal. The modal opens and contains the chart. But the chart in the modal doesn't render. If I do statehaschanged then the chart will render 1 time but not if i click on a different row.

//index.cs


public class ChartData
{
public string X { get; set;}
public double Y {get; set;}
}



//index.cs
private void LoadValueHistory(Model data)
{
LoadData(data.ObjectDataPoints);
ModalController.OpenModal(IndexPageModal.TrendableViewModal);

}
//index.cs
public void LoadData(ValueUpdate valueUpdate)
{
foreach (var value in valueUpdate.History)
{
var roundedValue = value.Value;
var formattedTimestamp = value.Timestamp.toString();
HistoricalData.Add(new ChartData { X = formattedTimestamp, Y = roundedValue });

}
}

//trendable modal.razor
<SfDialog Width="800px" @bind-Visible="@Visibility" IsModal="true" AllowPrerender="false">
<DialogTemplates>
<Header>Trendable View</Header>
<Content>
<SfChart Title="Trends">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Categories"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@HistoricalData" XName="X" YName="Y" Type="ChartSeriesType.Line">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
</div>
</Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="Close" IsPrimary="true" OnClick="@Close"></DialogButton>

</DialogButtons>
</SfDialog>

@code {

[Parameter]
public bool Visibility { get; set; }

[Parameter]
public EventCallback OnClose { get; set; }

[Parameter]
public List<ChartData> HistoricalData { get; set; } = new();

private void Close()
{
Visibility = false;
HistoricalData.Clear();
OnClose.InvokeAsync();
}

3 Replies 1 reply marked as answer

DG Durga Gopalakrishnan Syncfusion Team June 9, 2022 03:00 PM UTC

Hi Pavel,


Greetings from Syncfusion.


We suggest you to refresh the chart after dialog in opened using Opened event. We have prepared sample based on your requirement. Please check with the below snippet and screenshot.


<SfDialog>

        <DialogTemplates>

            <Content>

              <div style="height:100%; width:100%">

                        <SfChart @ref="chartObj"></SfChart>

              </div>

            </Content>

        </DialogTemplates>

        <DialogEvents Opened="@AfterOpen"></DialogEvents>

    </SfDialog>

<style>

.e-chart {

         height : inherit !important;

         width : inherit !important;

    }

@code {  

    SfChart chartObj;

    private void AfterOpen(Syncfusion.Blazor.Popups.OpenEventArgs args)

    {

        chartObj.Refresh();

    }

}



Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DialogChart-1412596310.zip


Kindly revert us if you have any concerns.


Regards,

Durga Gopalakrishnan.


Marked as answer

AL Alex June 9, 2022 04:57 PM UTC

Hi,

Why do we need to do this now?  



SB Swetha Babu Syncfusion Team June 14, 2022 03:18 AM UTC

Hi Alex,


When we open the dialog component, the chart has rendered before the dialog component gets opened. So, to make the chart visible, we are refreshing the Chart component in the open event of the Dialog component.


Kindly, revert us if you have any concerns,


Regards,

Swetha


Loader.
Up arrow icon