Skip to main content
A newer version of this page is available. .
All docs
V21.2

HierarchicalChartControlBase.Legend Property

Gets or sets a treemap/sunburst legend.

Namespace: DevExpress.Xpf.TreeMap

Assembly: DevExpress.Xpf.TreeMap.v21.2.dll

NuGet Package: DevExpress.Wpf.TreeMap

Declaration

public Legend Legend { get; set; }

Property Value

Type Description
Legend

An object of the Legend class.

Remarks

A legend contains descriptions of colors used to paint treemap/sunburst items. Each legend item includes the treemap item’s group name (if the group does not have nested groups) or the sunburst item’s root group name with the corresponding color marker.

Sunburst legend

Initialize the treemap/sunburst’s Legend property with a Legend object to add a legend to a treemap/sunburst.

Example: How to Add a Legend to a Treemap

This example adds a legend to a treemap and configures its title, border, and text settings.

Treemap legend

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TreemapExample"
        xmlns:dxtm="http://schemas.devexpress.com/winfx/2008/xaml/treemap" 
        x:Class="TreemapExample.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
            <dxtm:TreeMapControl x:Name="treemap">
                <dxtm:TreeMapControl.Colorizer>
                    <dxtm:TreeMapPaletteColorizer ColorizeGroups="True"/>
                </dxtm:TreeMapControl.Colorizer>
                <dxtm:TreeMapControl.Legend>
                    <dxtm:Legend HorizontalPosition="Center" VerticalPosition="BottomOutside" 
                                 Margin="10" Height="80" Padding="4" Direction="TopToBottom"
                                 BorderBrush="DarkGray" BorderThickness="1">
                        <dxtm:Legend.Title>
                            <dxtm:LegendTitle Content="Field of Activity" FontSize="16" FontWeight="Bold"/>
                        </dxtm:Legend.Title>
                    </dxtm:Legend>
                </dxtm:TreeMapControl.Legend>
                <!-- Data binding settings are skipped. -->
            </dxtm:TreeMapControl>
        </Border>
    </Grid>
</Window>

Example: How to Customize Legend Markers

Specify the Legend.ItemTemplate property to configure legend item appearance. For example, you can draw circular markers instead of rectangular markers in the legend:

Circular legend markers

<dxtm:TreeMapControl.Legend>
    <dxtm:Legend HorizontalPosition="Center" VerticalPosition="BottomOutside" 
                  Margin="10" Height="80"  Padding="4" Direction="TopToBottom" 
                  BorderBrush="DarkGray" BorderThickness="1">
        <dxtm:Legend.Title>
            <dxtm:LegendTitle Content="Field of Activity" FontSize="14" FontWeight="Bold"/>
        </dxtm:Legend.Title>
        <dxtm:Legend.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Ellipse Width="10" Height="10" Fill="{Binding Brush}" Margin="2,0"/>
                    <TextBlock Text="{Binding Text}"/>
                </StackPanel>
            </DataTemplate>
        </dxtm:Legend.ItemTemplate>
    </dxtm:Legend>
</dxtm:TreeMapControl.Legend>

Colorizer Specifics

A legend item’s marker appearance and text depends on the colorizer type that you use to color treemap/sunburst items.

The legend shows value ranges if a TreeMapRangeColorizer is applied to the treemap chart:

A legend with ranges

If you use a TreeMapGroupGradientColorizer or SunburstGroupGradientColorizer, the legend displays a gradient marker for legend items:

Gradient legend items

The legend is not displayed in the following cases:

Format Text in Legend

If you want to format legend item text, you should apply a colorizer to a treemap/sunburst and configure the colorizer’s TreeMapPaletteColorizerBase.LegendItemPattern (SunburstPaletteColorizerBase.LegendItemPattern) property.

See Also