How to perform zooming programmatically in Blazor Charts?
This article explains how to perform zooming programmatically in Blazor Charts.
Performing Zooming Programmatically:
Blazor Charts provides an option to perform zooming programmatically using the ZoomFactor property.
This can be achieved by setting and resetting the zoom level by adjusting the ZoomFactor value in ChartPrimaryXAxis and ChartPrimaryYAxis. For example, you can dynamically perform ZoomIn, ZoomOut, and Reset operations by clicking external buttons.
The code example below demonstrates how to perform zooming programmatically in a chart.
Index.razor:
@using Syncfusion.Blazor.Charts
@using Syncfusion.Blazor.Buttons
<SfButton @onclick="ZoomIn" IsToggle="true" IsPrimary="true" Content="ZoomIn"></SfButton>
<SfButton @onclick="ZoomOut" IsToggle="true" IsPrimary="true" Content="ZoomOut"></SfButton>
<SfButton @onclick="ResetZoom" IsToggle="true" IsPrimary="true" Content="ResetZoom"></SfButton>
<SfChart>
<ChartPrimaryXAxis ZoomFactor ="@SetZoomFactor" ValueType="Syncfusion.Blazor.Charts.ValueType.Category" />
<ChartPrimaryYAxis ZoomFactor="@SetZoomFactor" />
<ChartSeriesCollection>
<ChartSeries DataSource="@MedalDetails" XName="X" YName="Y" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double Y { get; set; }
}
public double SetZoomFactor = 1;
public List<ChartData> MedalDetails = new List<ChartData>
{
new ChartData { X= "South Korea", Y= 39.4 },
new ChartData { X= "India", Y= 61.3 },
new ChartData { X= "Pakistan", Y= 20.4 },
new ChartData { X= "Germany", Y= 65.1 },
new ChartData { X= "Australia", Y= 15.8 },
new ChartData { X= "Italy", Y= 29.2 },
new ChartData { X= "United Kingdom", Y= 44.6 },
new ChartData { X= "Saudi Arabia", Y= 9.7 },
new ChartData { X= "Russia", Y= 40.8 },
new ChartData { X= "Mexico", Y= 31 },
new ChartData { X= "Brazil", Y= 75.9 },
new ChartData { X= "China", Y= 51.4 }
};
public void ZoomIn()
{
SetZoomFactor -= 0.1;
}
public void ZoomOut()
{
SetZoomFactor += 0.1;
}
public void ResetZoom()
{
SetZoomFactor = 1;
}
}
The following screenshot illustrates the output of the code snippet.
Output:
Live Sample for Dynamic Zooming
Conclusion:
We hope you enjoyed learning how to perform zooming programmatically in the Blazor Chart component.
You can refer to our Blazor Chart feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Charts and other Blazor components.
If you have any questions 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!