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 feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Chart documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!