How to reset chart zooming programmatically in Blazor Charts?
This article explains how to reset chart zooming programmatically in Blazor Charts.
Reset Chart Zooming Programmatically
Blazor Charts provides an option to reset chart zooming programmatically.
To manually reset the zoom, you first need to set the ZoomFactor and ZoomPosition properties. In the OnZoomEnd event, retrieve the ZoomFactorand ZoomPosition values and assign them to the appropriate axis properties. Then, in a click event handler, reset the ZoomFactor and ZoomPosition properties by setting the ZoomFactor to a default value of 1 and the ZoomPosition to 0.
The below code example demonstrates how to reset chart zooming programmatically.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartEvents OnZoomEnd="OnZoomingEventEnd"></ChartEvents>
<ChartPrimaryXAxis ZoomFactor="@zoomFactorXAxis" ZoomPosition="@zoomPositionXAxis" ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime" IntervalType="IntervalType.Auto"
Format="hh:mm:ss" />
<ChartZoomSettings EnableMouseWheelZooming="true" EnablePinchZooming="true" EnableSelectionZooming="true" />
<ChartSeriesCollection>
<ChartSeries DataSource="@WeatherReports" XName="XValue" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column" />
</ChartSeriesCollection>
</SfChart>
<button DisplayName="Edit Source" IconCss="bi bi-pencil" @onclick="Reset">Reset Zooming</button>
@code {
private double zoomFactorXAxis = 1;
private double zoomFactorYAxis = 1;
private double zoomPositionXAxis = 0;
private double zoomPositionYAxis = 0;
private void Reset(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
zoomFactorXAxis = 1;
zoomFactorYAxis = 1;
zoomPositionXAxis = 0;
zoomPositionYAxis = 0;
}
public void OnZoomingEventEnd(Syncfusion.Blazor.Charts.ZoomingEventArgs args)
{
zoomFactorXAxis = args.AxisCollection[1].ZoomFactor;
zoomFactorYAxis = args.AxisCollection[3].ZoomFactor;
zoomPositionXAxis = args.AxisCollection[1].ZoomPosition;
zoomPositionYAxis = args.AxisCollection[3].ZoomPosition;
}
public List<ChartData> WeatherReports = new List<ChartData>
{
new ChartData { XValue = new DateTime(2005, 01, 01), YValue = 21 },
new ChartData { XValue = new DateTime(2006, 01, 01), YValue = 24 },
new ChartData { XValue = new DateTime(2007, 01, 01), YValue = 36 },
new ChartData { XValue = new DateTime(2008, 01, 01), YValue = 38 },
};
public class ChartData
{
public DateTime XValue { get; set; }
public double YValue { get; set; }
}
}
The following screenshot illustrates the output of the code snippet.
Live sample for reset chart zooming programmatically
Conclusion
I hope you enjoyed learning how to reset chart zooming programmatically in Blazor Charts.
You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!