OxyPlot legend items managing
Asked Answered
C

1

6

is there any way to manage items in legend? I mean e.q. remove some items from legend but not from whole plot? I know that each serie in plot is linked with one item in legend, but i want to break this rule and put to legend only selected series.

Thanks for your request.

Cumbersome answered 26/10, 2015 at 7:41 Comment(3)
If you does not assign a tittle to the series(lineseries, etc), it is not represented on the legend.Roentgen
Ah, that´s a good idea! Thanks a lot, i will try it.Cumbersome
Yes, thank you, it solved my problem.Cumbersome
R
22

If you don't assign a title to the series (LineSeries, etc), it won't be represented on the legend:

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
});

Starting v2.0.1, the legend doesn't automatically appear and all PlotModel.LegendXxx members have been removed. You now have to manually add one legend:

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
});
Roentgen answered 5/11, 2015 at 7:4 Comment(1)
Series also has a bool called RenderInLegend that you can use to hide the series in the legend.Raisin

© 2022 - 2025 — McMap. All rights reserved.