Skip to main content
A newer version of this page is available. .

AxisBase.Label Property

Specifies axis label settings.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v20.2.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Charts, DevExpress.Wpf.Charts

Declaration

public AxisLabel Label { get; set; }

Property Value

Type Description
AxisLabel

Contains axis label settings.

Remarks

The Chart Control generates labels based on series data. You can customize label appearance as follows:

<dxc:XYDiagram2D.AxisX>
 <dxc:AxisX2D Visible="True">
   <dxc:AxisX2D.Label>
     <dxc:AxisLabel Foreground="DarkSlateBlue" 
                    Background="Orange" 
                    FontSize="14" 
                    FontStyle="Italic" 
                    FontWeight="Bold"
                    Angle="-90"
                    TextPattern="{}{V} year"/>
   </dxc:AxisX2D.Label>
 </dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>

Use the ElementTemplate property to define a DataTemplate for axis labels:

<Window.Resources>
    <DataTemplate x:Key="AxisXLabelTemplate">
        <Border BorderThickness="1" CornerRadius="9" Opacity="1.0">
            <Border.Background>
                <SolidColorBrush Color="Orange"/>
            </Border.Background>
            <Label Content="{Binding Path=Content}" Padding="5,1,5,1.5" 
                   Foreground="DarkSlateBlue" FontSize="12" />
        </Border>
    </DataTemplate>
</Window.Resources>
...
<dxc:XYDiagram2D.AxisX>
    <dxc:AxisX2D Visible="True">
        <dxc:AxisX2D.Label>
            <dxc:AxisLabel ElementTemplate="{StaticResource AxisXLabelTemplate}"/>
        </dxc:AxisX2D.Label>
    </dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>

For more information, see the following help article: Axis Labels.

To display custom text in labels, create custom labels as described in the following help section: Axis Labels: Configure Custom Labels.

Example

You can specify label properties or define a data template for axis labels to change their appearance.

This example specifies the following properties for X-axis labels: Angle, Background, FontSize, FontStyle, FontWeight, Foreground, and TextPattern.

The example defines a data template for Y-axis labels. Assign this template to the ElementTemplate property to apply it to labels.

View Example

<Window.Resources>
        <DataTemplate x:Key="AxisXLabelTemplate">
            <Border BorderThickness="1" CornerRadius="9" Opacity="1.0">
                <Border.Background>
                    <SolidColorBrush Color="Orange"/>
                </Border.Background>
                <Label Content="{Binding Path=Content}" 
                       Padding="5,1,5,1.5" 
                       Foreground="DarkSlateBlue"
                       FontSize="12" />
            </Border>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <dxc:ChartControl x:Name="chartControl1" Width="540" Height="300" BorderThickness="1">
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.AxisX>
                        <dxc:AxisX2D Visible="True">
                            <dxc:AxisX2D.Label>
                                <dxc:AxisLabel Angle="-90"
                                               Background="Orange"   
                                               FontSize="14" 
                                               FontStyle="Italic" 
                                               FontWeight="Bold"
                                               Foreground="DarkSlateBlue"
                                               TextPattern="{}{V} year"/>
                            </dxc:AxisX2D.Label>
                        </dxc:AxisX2D>
                    </dxc:XYDiagram2D.AxisX>
                    <dxc:XYDiagram2D.AxisY>
                        <dxc:AxisY2D>
                            <dxc:AxisY2D.Label>
                                <dxc:AxisLabel ElementTemplate="{StaticResource AxisXLabelTemplate}"/>
                            </dxc:AxisY2D.Label>
                            <dxc:AxisY2D.WholeRange>
                                <dxc:Range  MinValue="450"/>
                            </dxc:AxisY2D.WholeRange>
                        </dxc:AxisY2D>
                    </dxc:XYDiagram2D.AxisY>
                    <!--...-->
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Label property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also