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.