Class CartesianDataLabelSettings
The CartesianDataLabelSettings class is used to customize the appearance of cartesian series data labels.
Inherited Members
Namespace: Syncfusion.UI.Xaml.Charts
Assembly: Syncfusion.Chart.WinUI.dll
Syntax
public sealed class CartesianDataLabelSettings : ChartDataLabelSettings
Remarks
To customize data labels, create an instance of CartesianDataLabelSettings class, and set it to the DataLabelSettings property of a cartesian series.
ShowDataLabels
Data labels can be added to a chart series by enabling the
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:LineSeries ItemsSource ="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True"/>
</chart:SfCartesianChart>
ContentTemplate
The appearance of the data label can be customized using the ContentTemplate property of CartesianDataLabelSettings.
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:LineSeries ItemsSource ="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:LineSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings>
<chart:CartesianDataLabelSettings.ContentTemplate>
<DataTemplate>
<StackPanel Margin = "10" Orientation="Vertical">
<Ellipse Height = "15" Width="15" Fill="Cyan"
Stroke="#4a4a4a" StrokeThickness="2"/>
<TextBlock HorizontalAlignment = "Center" FontSize="12"
Foreground="Black" FontWeight="SemiBold"
Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</chart:CartesianDataLabelSettings.ContentTemplate>
</chart:CartesianDataLabelSettings>
</chart:LineSeries.DataLabelSettings>
</chart:LineSeries>
</chart:SfCartesianChart>
Context
To customize the content of data labels, it offers Context property.
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:LineSeries ItemsSource ="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:LineSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings Context="Percentage" />
</chart:LineSeries.DataLabelSettings>
<chart:LineSeries />
</chart:SfCartesianChart>
Customization
To change the appearance of data labels, it offers BorderBrush, BorderThickness, Margin, Foreground, Background, FontStyle, FontSize, and FontFamily options.
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:LineSeries ItemsSource ="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:LineSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings Foreground="White" FontSize="11"
FontFamily="Calibri" BorderBrush="Black" BorderThickness="1" Margin="1"
FontStyle="Italic" Background="#1E88E5" />
</chart:LineSeries.DataLabelSettings>
<chart:LineSeries />
</chart:SfCartesianChart>
ConnectorLine
A connector line is used to connect the label and data point using a line. The
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:LineSeries ItemsSource ="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:LineSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings ConnectorHeight = "40" ShowConnectorLine="True">
<chart:CartesianDataLabelSettings.ConnectorLineStyle>
<Style TargetType = "Path">
<Setter Property="StrokeDashArray" Value="5,3"/>
</Style>
</chart:CartesianDataLabelSettings.ConnectorLineStyle>
</chart:CartesianDataLabelSettings>
</chart:LineSeries.DataLabelSettings>
</chart:LineSeries>
</chart:SfCartesianChart>
Constructors
CartesianDataLabelSettings()
Initializes a new instance of the CartesianDataLabelSettings class.
Declaration
public CartesianDataLabelSettings()
Fields
BarLabelAlignmentProperty
Identifies the BarLabelAlignment dependency property.
Declaration
public static readonly DependencyProperty BarLabelAlignmentProperty
Field Value
Type | Description |
---|---|
Microsoft.UI.Xaml.DependencyProperty | The identifier for |
PositionProperty
Identifies the Position dependency property.
Declaration
public static readonly DependencyProperty PositionProperty
Field Value
Type | Description |
---|---|
Microsoft.UI.Xaml.DependencyProperty | The identifier for |
Properties
BarLabelAlignment
Gets or sets the value for a bar chart data label's alignment.
Declaration
public BarLabelAlignment BarLabelAlignment { get; set; }
Property Value
Type | Description |
---|---|
BarLabelAlignment | It accepts BarLabelAlignment values and has a default value of Top. |
Remarks
CartesianDataLabelSettings also allows you to define label alignment with the HorizontalAlignment and VerticalAlignment properties.
Examples
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:ColumnSeries ItemsSource="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:ColumnSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings BarLabelAlignment="Middle" />
</chart:ColumnSeries.DataLabelSettings>
</chart:ColumnSeries>
</chart:SfCartesianChart>
Position
Gets or sets the value for the data label's position.
Declaration
public DataLabelPosition Position { get; set; }
Property Value
Type | Description |
---|---|
DataLabelPosition | It accepts DataLabelPosition values and its default value is Default. |
Remarks
It is used to position the data labels at the center, inner, and outer positions of the actual data point position.
Examples
<chart:SfCartesianChart>
<!-- ... Eliminated for simplicity-->
<chart:ColumnSeries ItemsSource="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ShowDataLabels="True">
<chart:ColumnSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings Position="Outer" />
</chart:ColumnSeries.DataLabelSettings>
</chart:ColumnSeries>
</chart:SfCartesianChart>