首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Livecharts更改默认图例

Livecharts更改默认图例
EN

Stack Overflow用户
提问于 2017-11-27 12:12:39
回答 1查看 5.7K关注 0票数 0

这是我的问题。

我正在使用LiveCharts显示一些数据。一切都很好,直到显示表示所有显示的数据的图例为止。

图例图

是否有可能根据颜色(中风)或DefaultGeometries来显示图例?

提前感谢你的帮助,

迭戈

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-08 16:33:09

我知道现在有点晚了,但我也想做些类似的事情,所以我想出个办法。

您需要创建一个新的集合,并遵循活字图能量预测的示例。

首先,您需要为图表设置LegendLocation=“无”

代码语言:javascript
复制
<wpf:CartesianChart Hoverable="False" DataTooltip="{x:Null}" DisableAnimations="True" LegendLocation="None" Series="{Binding AllSeries, ElementName=FastGraphRoot}">

新的传奇代码(.xaml中重要的部分):

代码语言:javascript
复制
<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>

绑定列表将来自原始系列,但分组后,我使用了一个属性:

代码语言:javascript
复制
private SeriesCollection _allSeriesGroupByName = new SeriesCollection();
public SeriesCollection AllSeriesGroupByName { get { return _allSeriesGroupByName; } set { _allSeriesGroupByName = value; OnPropertyChanged(); } }

您可以简单地用以下代码填充它(或者任何您认为更快的代码):

代码语言:javascript
复制
var col = collection.GroupBy(g => ((LineSeries)g).Stroke).Select(p => p.First());
AllSeriesGroupByName = new SeriesCollection();
foreach (var c in col)
{
    AllSeriesGroupByName.Add(c);
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47510737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档