Articles in this section
Category / Section

How to Display Numeric Axis Labels in Blazor Charts?

3 mins read

This article explains how to display numeric axis labels as integers after zooming in Blazor Charts.

Displaying axis labels in integer after zooming

Blazor Charts provides an option to display numeric axis labels only as integers after performing zooming in the chart, using the OnAxisActualRangeCalculated event.

This can be achieved by rounding the Interval value of the numeric axis in the OnAxisActualRangeCalculated event by checking if the argument’s axis name is PrimaryYAxis. This will render interval values as integer even after zooming the chart.

The following code example demonstrates how to display numeric axis labels as integers.

Index.razor

@using Syncfusion.Blazor.Charts
<SfChart>
   <ChartEvents OnAxisActualRangeCalculated="RangeCalculated"></ChartEvents>
   <ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
   <ChartSeriesCollection>
       <ChartSeries DataSource="@Sales" XName="Month" YName="SalesValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Column">
       </ChartSeries>
   </ChartSeriesCollection>
   <ChartZoomSettings EnableSelectionZooming="true"></ChartZoomSettings>
</SfChart>

@code {
   public void RangeCalculated(AxisRangeCalculatedEventArgs Args)
   {
       if (Args.AxisName == "PrimaryYAxis")
       {
          Args.Interval = Math.Round(Args.Interval);
       }
   }

   public class SalesInfo
   {
       public string Month { get; set;}
       public double SalesValue { get; set;}
   }

   public List<SalesInfo> Sales = new List<SalesInfo>
   {
       new SalesInfo { Month = "Jan", SalesValue = 35 },
       new SalesInfo { Month = "Feb", SalesValue = 28 },
       new SalesInfo { Month = "Mar", SalesValue = 34 },
       new SalesInfo { Month = "Apr", SalesValue = 32 },
       new SalesInfo { Month = "May", SalesValue = 40 },
       new SalesInfo { Month = "Jun", SalesValue = 32 },
       new SalesInfo { Month = "Jul", SalesValue = 35 }
   };
} 

Output

image.png

Live sample for displaying Integers

Conclusion:

We hope you enjoyed learning how to display axis labels as integers after zooming 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied