wpfoxyplot

OxyPlot legend items managing


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.


Solution

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