Articles in this section
Category / Section

How to format y-axis labels and tooltips in a Blazor Chart?

3 mins read

This article explains how to format y-axis labels and tooltips in a Blazor Chart using properties and events.

Formatting Y-Axis Labels and Tooltip

Blazor Charts provides an option to format the y-axis labels using the LabelFormat property and OnAxisLabelRender event.

To view the chart series tooltip text and y-axis labels in different formats, you need to specify the required format for tooltips in the axis LabelFormat property, then you can change the axis label format in the OnAxisLabelRender event. Using this, you can view labels and tooltips in the required format.

The code example below demonstrates how to format axis labels and tooltips.

Index.razor:

@using Syncfusion.Blazor.Charts
@code{
 string labelformat = "N";
 string labelformat2 = "N10";
}
<input type="text" @bind="@labelformat" />
<input type="text" @bind="@labelformat2" />
<SfChart>
 <ChartPrimaryYAxis LabelFormat="@labelformat2" ValueType="Syncfusion.Blazor.Charts.ValueType.Double">
 </ChartPrimaryYAxis>
 <ChartPrimaryXAxis LabelFormat="yyyy" Format="M/dd/yyyy" EnableAutoIntervalOnZooming="true" IntervalType="IntervalType.Hours" ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime"></ChartPrimaryXAxis>
 <ChartTooltipSettings Enable="true">
 </ChartTooltipSettings>
 <ChartEvents OnAxisLabelRender="AxisLabelEvent"></ChartEvents>
 <ChartSeriesCollection>
     <ChartSeries DataSource="@Data" XName="XValue" YName="YValue">
         <ChartMarker Visible="true" />
     </ChartSeries>
 </ChartSeriesCollection>
</SfChart>
@code{
 public class ChartData
 {
     public DateTime XValue { get; set; }
     public double YValue { get; set; }
 }
 public List<ChartData> Data = getchart();
 public static List<ChartData> getchart()
 {
     Random random = new Random();
     List<ChartData> newchart = new();
     for (int i = 0; i < 1000; i++)
     {
         DateTime xValue = DateTime.UtcNow.AddDays(i + 1);
         double yValue = random.NextDouble();
         newchart.Add(new ChartData { XValue = xValue, YValue = yValue });
     }
     return newchart;
 }
 public void AxisLabelEvent(AxisLabelRenderEventArgs args)
 {
     double axisLabel = Convert.ToDouble(args.Text);
     args.Text = axisLabel.ToString(labelformat);
 }
} 

The following screenshot illustrates the output of the code snippet.

Output:

image.png

Tooltip Format Demo

Conclusion:

We hope you enjoyed learning how to format y-axis labels and tooltips in different formats 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