How to customize the data label’s font in .NET MAUI Chart (SfCartesianChart)?
This article explains how to customize the font of the data labels in .NET MAUI Cartesian Charts. The .NET MAUI Chart allows you to customize the font of the data labels using the LabelStyle property of the ChartDataLabelSettings. This property provides options to change the font size, font family, font attributes, and label format of the data labels.
The following code demonstrates how to customize the font of the data labels.
XAML
<chart:SfCartesianChart>
. . .
<chart:ColumnSeries ItemsSource="{Binding Data}" XBindingPath="Source"
YBindingPath="Traffic" ShowDataLabels="True">
<chart:ColumnSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings>
<chart:CartesianDataLabelSettings.LabelStyle>
<chart:ChartDataLabelStyle FontSize="16" FontAttributes="None"
FontFamily="OpenSans-Regular" LabelFormat="0.0M"/>
</chart:CartesianDataLabelSettings.LabelStyle>
</chart:CartesianDataLabelSettings>
</chart:ColumnSeries.DataLabelSettings>
</chart:ColumnSeries>
</chart:SfCartesianChart>
C#
SfCartesianChart chart = new SfCartesianChart();
. . .
ColumnSeries series = new ColumnSeries()
{
ItemsSource = viewModel.Data,
XBindingPath = "Source",
YBindingPath = "Traffic",
ShowDataLabels = true
};
series.DataLabelSettings.LabelStyle = new ChartDataLabelStyle()
{
FontSize = 16,
FontAttributes = FontAttributes.None,
FontFamily = "OpenSans-Regular",
LabelFormat = "0.0M"
};
chart.Series.Add(series);
Output:
Conclusion
I hope you enjoyed learning how to customize the font of the data labels in the .NET MAUI Chart (SfCartesianChart).
You can refer to our .NET MAUI Chart’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our .NET MAUI Chart documentation to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!