OxyPlot图例项管理

6

有没有办法管理图例中的项目?我的意思是,例如从图例中删除某些项目,但不是从整个图中删除?我知道图中的每个系列都与图例中的一个项目相关联,但我想打破这个规则,并仅将选定的系列放入图例中。

感谢您的请求。


5
如果您没有给系列(如折线图等)指定标题,它将不会显示在图例上。 - Jose
啊,这是个好主意!非常感谢,我会尝试的。 - Shadow2334
是的,谢谢,它解决了我的问题。 - Shadow2334
1个回答

21
如果您不为系列(LineSeries等)分配标题,则它将不会在图例中显示:
如果您不为系列(LineSeries等)分配标题,则它将不会在图例中显示:
var plotModel = new PlotModel();
plotModel.LegendTitle = "Legend";
plotModel.LegendPosition = LegendPosition.RightBottom;

plotModel.Series.Add(new LineSeries
{
    ItemsSource = someItemSource,
    Color = OxyColors.Red,
    //Title = "title" <- Title commented
});

从 v2.0.1 开始,图例不再自动显示,并且所有的 PlotModel.LegendXxx 成员已被移除。现在您需要手动添加一个图例:

var plotModel = new PlotModel();
plotModel.Legends.Add(new Legend() { 
    LegendTitle = "Legend",
    LegendPosition = LegendPosition.RightBottom,
});

plotModel.Series.Add(new LineSeries
{
    ItemsSource = someItemSource,
    Color = OxyColors.Red,
    //Title = "title" <- Title commented
});

2
Series 还有一个名为 RenderInLegendbool,您可以使用它来在图例中隐藏系列。 - HDL_CinC_Dragon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接