Skip to main content

CartesianSeriesView.LegendPattern Property

Specifies a string pattern that formats legend item text for series.

Namespace: DevExpress.WinUI.Charts

Assembly: DevExpress.WinUI.Charts.v23.2.dll

NuGet Package: DevExpress.WinUI

Declaration

[DP("{S}")]
public string LegendPattern { get; set; }

Property Value

Type Description
String

A format string.

Remarks

Use the LegendPattern property to define a pattern that formats the displayed text within the legend. Various placeholders enclosed in braces correspond to the available display patterns.

The following table lists available placeholders:

Placeholder Description
{S} Displays the series name. Before you use this placeholder, specify the SeriesBase.DisplayName property.
{G} Displays the name of a stacked group.

If a pattern starts with a placeholder in the XAML markup, insert empty brackets into the beginning of the pattern as follows: “{}{V}”.

If a legend shows point data, use the SeriesView.LegendPointPattern property to format legend text.

Example

The following markup formats text shown in the legend for series:

Formatted legend text

<Grid.DataContext>
    <local:ChartViewModel/>
</Grid.DataContext>
<Charts:CartesianChart x:Name="chart"
                       SeriesSource="{Binding SeriesData}">
    <Charts:CartesianChart.SeriesItemTemplate>
        <DataTemplate>
            <Charts:Series DisplayName="{Binding Name}">
                <Charts:Series.Data>
                    <Charts:DataSource PointSource="{Binding DataPoints}"
                                       ArgumentDataMember="Argument"
                                       ValueDataMember="Value"/>
                </Charts:Series.Data>
                <Charts:Series.View>
                    <Charts:BarSeriesView StackedMode="Stacked"
                                          StackedGroup="{Binding Group}"
                                          LegendPattern="{}{S} (Group: {G})"/>
                </Charts:Series.View>
            </Charts:Series>
        </DataTemplate>
    </Charts:CartesianChart.SeriesItemTemplate>
    <!--...-->
</Charts:CartesianChart>
using DevExpress.Mvvm;
using Microsoft.UI.Xaml;
using System.Collections.Generic;

namespace StackedSeriesChart {

    public sealed partial class MainWindow : Window {
        public ChartViewModel ViewModel { get; } = new ChartViewModel();
        public MainWindow() {
            this.InitializeComponent();
        }
    }
    public class ChartViewModel : ViewModelBase {
        public List<SeriesViewModel> SeriesData { get; }
        public ChartViewModel() {
            List<SeriesViewModel> seriesData = new List<SeriesViewModel> {
                new SeriesViewModel{ Name = "Canada", Group = 0,
                    DataPoints = new List<DataPoint> {
                        new DataPoint{ Argument = "March", Value = 125.45 },
                        new DataPoint{ Argument = "April", Value = 144.3 },
                        new DataPoint{ Argument = "May", Value = 133.54 }
                    }
                },
                new SeriesViewModel{ Name = "USA", Group = 0,
                    DataPoints = new List<DataPoint> {
                        new DataPoint{ Argument = "March", Value = 122.36 },
                        new DataPoint{ Argument = "April", Value = 126.87 },
                        new DataPoint{ Argument = "May", Value = 128.33 }
                    }
                },
                new SeriesViewModel{ Name = "France", Group = 1,
                    DataPoints = new List<DataPoint> {
                        new DataPoint{ Argument = "March", Value = 56.32 },
                        new DataPoint{ Argument = "April", Value = 58.63 },
                        new DataPoint{ Argument = "May", Value = 59.14 }
                    }
                },
                new SeriesViewModel{ Name = "Germany", Group = 1,
                    DataPoints = new List<DataPoint> {
                        new DataPoint{ Argument = "March", Value = 62.12 },
                        new DataPoint{ Argument = "April", Value = 69.123 },
                        new DataPoint{ Argument = "May", Value = 75.11 }
                    }
                },
                new SeriesViewModel{ Name = "Austria", Group = 1,
                    DataPoints = new List<DataPoint> {
                        new DataPoint{ Argument = "March", Value = 42.852 },
                        new DataPoint{ Argument = "April", Value = 41.77 },
                        new DataPoint{ Argument = "May", Value = 39.25 }
                    }
                }
            };
            SeriesData = seriesData;
        }
    }
    public class SeriesViewModel {
        public int Group { get; set; }
        public string Name { get; set; }
        public List<DataPoint> DataPoints { get; set; }
    }
    public class DataPoint {
        public string Argument { get; set; }
        public double Value { get; set; }

    }
}
See Also