这是我的问题。
我正在使用 LiveCharts 来显示一些数据。一切都很好,直到显示代表所有显示数据的图例。
是否可以根据例如颜色(描边)或 DefaultGeometries 显示图例?
在此先感谢您的帮助,
迭戈
这是我的问题。
我正在使用 LiveCharts 来显示一些数据。一切都很好,直到显示代表所有显示数据的图例。
是否可以根据例如颜色(描边)或 DefaultGeometries 显示图例?
在此先感谢您的帮助,
迭戈
我知道这有点晚了,但我想做类似的事情,所以这就是我能想到的。
您需要创建一个新集合并按照Live Charts Energy Predictions的示例进行操作。
首先,您需要为图表设置 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>
绑定列表将来自原始系列但已分组,我为此使用了一个属性:
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);
}