Я знаю, что это немного поздно, но я хотел сделать что-то подобное, так что вот что я смог придумать.
Вам нужно будет создать новую коллекцию и следовать примеру для Живые графики прогнозов энергии< /а>.
Сначала вам нужно установить LegendLocation="None" для диаграммы.
<wpf:CartesianChart Hoverable="False" DataTooltip="{x:Null}" DisableAnimations="True" LegendLocation="None" Series="{Binding AllSeries, ElementName=FastGraphRoot}">
Новый код легенды (важная часть в .xaml):
<ListBox Name="ListBox" MinHeight="250" ItemsSource="{Binding AllSeriesGroupByName, ElementName=FastGraphRoot}" Panel.ZIndex="1" BorderThickness="0" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type wpf:LineSeries}">
<TextBlock Text="{Binding Title}"
Foreground="{Binding Stroke}"
FontSize="24"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Список Binded будет исходить из исходной серии, но сгруппирован, для этого я использовал свойство:
private SeriesCollection _allSeriesGroupByName = new SeriesCollection();
public SeriesCollection AllSeriesGroupByName { get { return _allSeriesGroupByName; } set { _allSeriesGroupByName = value; OnPropertyChanged(); } }
вы можете заполнить его просто этим кодом (или любым другим, который, по вашему мнению, будет быстрее):
var col = collection.GroupBy(g => ((LineSeries)g).Stroke).Select(p => p.First());
AllSeriesGroupByName = new SeriesCollection();
foreach (var c in col)
{
AllSeriesGroupByName.Add(c);
}
person
doogie
schedule
08.12.2017