How to individually zoom Y axis or X axis in the Blazor Chart?
This article explains how to customize the zoom functionality to individually zoom the y-axis or x-axis in the Blazor Chart Component.
Adjusting Zoom Mode in Blazor Chart Component
Blazor Chart provides support for customizing the zoom mode by using the Mode property in ChartZoomSettings. This property determines whether the chart can scale along the horizontal or vertical axes. The default value of the mode is XY (both axes).
Mode property in includes the following zooming mode option:
- X - Allows us to zoom the chart horizontally.
- Y - Allows us to zoom the chart vertically.
- XY - Allows us to zoom the chart both vertically and horizontally.
In the below code example, the Mode property is set to X. This will allow you to zoom only along X-axis while the zooming along Y axis is restricted.
Index.razor
@using Syncfusion.Blazor.Charts
<SfChart Title="Sales History of Product X">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartZoomSettings EnableSelectionZooming="true" Mode="ZoomMode.X"></ChartZoomSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesReports" XName="X" YName="YValue" Type="ChartSeriesType.Column"></ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
}
public List<ChartData> SalesReports = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46 },
new ChartData { X= "GBR", YValue= 27 },
new ChartData { X= "CHN", YValue= 15 },
new ChartData { X= "UK", YValue= 20 },
new ChartData { X= "AUS", YValue= 50 },
new ChartData { X= "IND", YValue= 26 },
new ChartData { X= "DEN", YValue= 30 },
new ChartData { X= "MEX", YValue= 26 },
};
}
The following image illustrates the output of the above code snippet.
Output:
Conclusion
I hope you enjoyed learning how to zoom X-axis or Y-axis alone in Blazor Chart Component.
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!