Delay with chart zoom

Hello!


I am using a SfSpinner to display the loading of a chart bgefore it finishes loading.

The spinner is binding visible with the bool before data loading and after data loading.

When using the chart, if zoom in on the chart and the data changes, the zoom stated

does not change. 

But when I use a delay for the spinner (e.g. Task.Delay(500)), and change the data, the zoom is reset.

is there any way to keep the zoom state even when using the Delay?


Thank you.


3 Replies

DG Durga Gopalakrishnan Syncfusion Team March 14, 2024 11:24 AM UTC

Hi Jylee,


Greetings from Syncfusion.


Your requirement can be achieved by changing the zoomfactor and zoomposition. We suggest you to store the calculated zoomfactor and zoomposition value in OnZoomEnd event after performing zooming. Then while updating the chart with new data, you can update the zoomfactor and zoomposition values using StateHasChanged method.


<SfButton Content="Update" @onclick="ChangeData" IsPrimary="true"></SfButton>

<SfChart>

   ChartEvents OnZoomEnd="OnZoomingEvent"></ChartEvents>

   <ChartPrimaryXAxis ZoomFactor="@zoomFactor" ZoomPosition="@zoomPosition">

   </ChartPrimaryXAxis>

</SfChart>

@code {

    public double zoomFactor = 1;

    public double zoomPosition = 0;

    public void OnZoomingEvent(ZoomingEventArgs args)

    {

        zoomFactor = args.AxisCollection[0].ZoomFactor;

        zoomPosition = args.AxisCollection[0].ZoomPosition;

    }

public void ChangeData(MouseEventArgs args)

{

    ChartData = new List<LineChartData>

    {

      new LineChartData { Period = new DateTime(2012, 01, 01), Can_Growth = 31, Viet_Growth = 59 },

      //…

     };

     StateHasChanged();

}

}


Before Update


After Update



Sample : https://blazorplayground.syncfusion.com/BZhJDqspqwIywYLv


Kindly revert us if you have any other concerns.


Regards,

Durga Gopalakrishnan.



JY JY March 18, 2024 02:47 AM UTC

This code and idea are very helpful!


Thank you very much!



DG Durga Gopalakrishnan Syncfusion Team March 18, 2024 05:24 AM UTC

Most welcome. Please get back to us if you have any other concerns. We are always happy in assisting you.


Loader.
Up arrow icon