Current filter:
                                You should refresh the page.
                                Support Center

                                How to display custom information in the legend

                                0

                                This example demonstrates how to calculate a total of values displayed by each legend item, and show this total in the legend. This can be done by utilizing a ControlTemplate with a Grid, containing a LegendItemsControl (for displaying legend items) and a TextBlock (showing the result). The summary is calculated in the chart control's BoundDataChanged event handler, and assigned to the DataContext property of the legend, to provide this value for the TextBlock's text. In the ControlTemplate, the Border's appearance properties (Background, BorderThickness, BorderBrush and Padding) and the LegendItemsControl's properties (ItemTemplate and ItemsSource) are bound to similar properties of the legend. You can customize the legend's layout and appearance as required, using this sample as a starting point.

                                See also:
                                - How to display check boxes for legend items to control the visibility of series;
                                - How to customize chart titles.


                                You must  log in  or  register  to leave comments
                                Select file
                                • MainWindow.xaml
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2010 vol 2.3 - v2013 vol 2.9
                                • v2010 vol 1.5 - v2010 vol 1.12
                                <Window x:Class="LegendCustomization.MainWindow"
                                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"        
                                        xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
                                        Title="Legend Cutomization" Height="350" Width="525">
                                    <Window.Resources>
                                        <collections:ArrayList x:Key="data">
                                            <Point X="1" Y="12.35" />
                                            <Point X="2" Y="11.02" />
                                            <Point X="3" Y="7.98" />
                                            <Point X="4" Y="13.36" />
                                            <Point X="5" Y="6.54" />
                                            <Point X="6" Y="9.11" />
                                        </collections:ArrayList>
                                    </Window.Resources>
                                    <Grid>
                                        <dxc:ChartControl x:Name="chart" BoundDataChanged="chart_BoundDataChanged">
                                            <dxc:ChartControl.Legend>
                                                <dxc:Legend>
                                                    <dxc:Legend.Template>
                                                        <ControlTemplate TargetType="dxc:Legend">
                                                            <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" 
                                                                    BorderBrush="{TemplateBinding BorderBrush}" Padding="{TemplateBinding Padding}">
                                                                <Grid>
                                                                    <Grid.RowDefinitions>
                                                                        <RowDefinition />
                                                                        <RowDefinition />
                                                                    </Grid.RowDefinitions>
                                                                    <dxc:LegendItemsControl
                                                                        ItemTemplate="{TemplateBinding ItemTemplate}"
                                                                        ItemsSource="{Binding Path=Items, RelativeSource={RelativeSource TemplatedParent}}">
                                                                        <dxc:LegendItemsControl.ItemsPanel>
                                                                            <ItemsPanelTemplate>
                                                                                <WrapPanel Orientation="Vertical"/>
                                                                            </ItemsPanelTemplate>
                                                                        </dxc:LegendItemsControl.ItemsPanel>
                                                                    </dxc:LegendItemsControl>
                                                                        
                                                                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                                                                        <TextBlock Text="Total: " Foreground="Black" />
                                                                        <TextBlock Text="{Binding}" />
                                                                    </StackPanel>
                                                                </Grid>
                                                            </Border>
                                                        </ControlTemplate>
                                                    </dxc:Legend.Template>
                                                </dxc:Legend>
                                            </dxc:ChartControl.Legend>
                                            <dxc:ChartControl.Diagram>
                                                <dxc:SimpleDiagram2D>
                                                    <dxc:SimpleDiagram2D.Series>
                                                        <dxc:PieSeries2D x:Name="series" DataSource="{StaticResource ResourceKey=data}" ArgumentDataMember="X" ValueDataMember="Y">
                                                            <dxc:PieSeries2D.LegendPointOptions>
                                                                <dxc:PointOptions PointView="Values">
                                                                    <dxc:PercentView.PercentOptions>
                                                                        <dxc:PercentOptions ValueAsPercent="False" />
                                                                    </dxc:PercentView.PercentOptions>
                                                                </dxc:PointOptions>
                                                            </dxc:PieSeries2D.LegendPointOptions>
                                                        </dxc:PieSeries2D>
                                                    </dxc:SimpleDiagram2D.Series>
                                                </dxc:SimpleDiagram2D>
                                            </dxc:ChartControl.Diagram>
                                        </dxc:ChartControl>
                                    </Grid>
                                </Window>

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners