How to add a prefix and suffix to the axis labels in the Blazor Chart?
This article explains how to add a prefix and suffix to the axis labels in the Blazor Chart Component.
Adding Prefix and Suffix to Axis Labels in Blazor Chart
The Blazor Chart provides support for formatting axis labels using global formatting options like ‘N’, ‘C’, and ‘P’ through the LabelFormat property of the respective axis (X or Y) which you want to format the axis labels. Additionally, the axis supports the inclusion of prefixes and suffixes to the labels using placeholders such as ${value}K
, where “value” represents the axis label, for instance, $20K.
The following code example demonstrates how to add prefix and suffix to the Y-axis labels in the Blazor Chart:
Index.razor
@using Syncfusion.Blazor.Charts
<sfchart>
<chartprimaryyaxis labelformat="${value}K" rangepadding="ChartRangePadding.Auto">
<chartprimaryxaxis rangepadding="ChartRangePadding.Auto">
<chartseriescollection>
<chartseries datasource="@Data" xname="XValue" yname="YValue" type="ChartSeriesType.Column">
</chartseries></chartseriescollection>
</chartprimaryxaxis></chartprimaryyaxis></sfchart>
@code {
public class ChartData
{
public double XValue { get; set; }
public double YValue { get; set; }
}
public List<chartdata> Data = new List<chartdata>
{
new ChartData { XValue = 10, YValue = 21 },
new ChartData { XValue = 20, YValue = 24 },
new ChartData { XValue = 30, YValue = 36 },
new ChartData { XValue = 40, YValue = 38 },
new ChartData { XValue = 50, YValue = 54 },
new ChartData { XValue = 60, YValue = 57 },
new ChartData { XValue = 70, YValue = 70 },
};
}
The following screenshot illustrates the output of the above code snippet.
Output
Conclusion
I hope you enjoyed learning how to add a prefix and suffix for axis labels in the 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!