How to specify chart culture using different methods in Blazor Charts?
This article explains how to specify chart culture using different methods in Blazor Charts.
Specify Chart Culture Using Different Methods
Blazor Charts provides an option to specify chart culture using different methods.
There are two ways to change the culture. The first method involves changing the culture in the Program.cs file. The second method allows you to modify a specific axis label by culture using the OnAxisLabelRender event.
The below code example demonstrates how to specify chart culture using different methods
Program.cs
In this code snippet, the British culture is specified.
using Culture.Data;
using Culture.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Syncfusion.Blazor;
using System.Globalization;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSyncfusionBlazor();
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-GB");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-GB");
var app = builder.Build();
...
Index.razor.cs
In this code snippet, use the OnAxisLabelRender event to replace the Text argument with South African culture.
@using Syncfusion.Blazor.Charts
@using System.Globalization;
<SfChart>
<ChartEvents OnAxisLabelRender="AxisLabelEvent"></ChartEvents>
<ChartPrimaryXAxis LabelFormat="c" />
<ChartPrimaryYAxis LabelFormat="c" />
<ChartSeriesCollection>
<ChartSeries DataSource="@SalesReports" XName="X" YName="Y" Type="ChartSeriesType.Column" Name="Product X">
</ChartSeries>
<ChartSeries DataSource="@SalesReports" XName="X" YName="Y1" Type="ChartSeriesType.Column" Name="Product Y">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public double X { get; set; }
public double Y { get; set; }
public double Y1 { get; set; }
}
public void AxisLabelEvent(AxisLabelRenderEventArgs args)
{
CultureInfo culture = new CultureInfo("en-ZA");
if (args.Axis.Name == "PrimaryXAxis")
{
args.Text = args.Text.Replace(CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol, culture.NumberFormat.CurrencySymbol);
}
}
public List<ChartData> SalesReports = new List<ChartData>
{
new ChartData{ X= 1900, Y= 123456, Y1= 434222 },
new ChartData{ X= 1920, Y= 343423, Y1= 734223 },
new ChartData{ X= 1940, Y= 645345, Y1= 354324},
new ChartData{ X= 1960, Y= 855464, Y1= 523423 },
new ChartData{ X= 1980, Y= 345464, Y1= 745332 },
new ChartData{ X= 2000, Y= 845334, Y1= 243435 }
};
}
The following screenshot illustrates the output of the code snippet.
Live sample for specifying chart culture using different methods
Conclusion
I hope you enjoyed learning how to specify chart culture using different methods in Blazor Charts.
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!