Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OxyPlot legend items managing

Tags:

wpf

oxyplot

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.

like image 798
Shadow2334 Avatar asked Dec 08 '22 01:12

Shadow2334


1 Answers

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
});
like image 142
Jose Avatar answered Dec 11 '22 07:12

Jose