这是我的问题。
我正在使用LiveCharts显示一些数据。一切都很好,直到显示表示所有显示的数据的图例为止。
是否有可能根据颜色(中风)或DefaultGeometries来显示图例?
提前感谢你的帮助,
迭戈
发布于 2017-12-08 16:33:09
我知道现在有点晚了,但我也想做些类似的事情,所以我想出个办法。
您需要创建一个新的集合,并遵循活字图能量预测的示例。
首先,您需要为图表设置LegendLocation=“无”
<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);
}https://stackoverflow.com/questions/47510737
复制相似问题