1

Closed

Legend is not visible

description

I have currently run into some issues with Oxyplot. When creating a plot on a WPF grid, I need a legend for three series to be represented in the legend. However, when I try to set IsLegendVisible to true for my plot model or change any of the orientation, position, or placement, the legend is not visible at all. Would anyone have any ideas on how to address this problem?
Closed Aug 6, 2014 at 7:56 PM by objo

comments

Videodrome18 wrote Jul 31, 2014 at 2:22 PM

plotModel.IsLegendVisible = true;
plotModel.LegendPlacement = LegendPlacement.Inside;
plotModel.LegendPosition = LegendPosition.RightMiddle;
plotModel.LegendOrientation = LegendOrientation.Vertical;

I have set these as the legend properties for the PlotModel and made sure to
call InvalidatePlot(true) afterwards to update the plot.

objo wrote Aug 6, 2014 at 9:06 AM

I tried the following code, but cannot reproduce the error:
        [Example("#10237: Legend is not visible")]
        public static PlotModel LegendIsNotVisible()
        {
            var plotModel = new PlotModel
            {
                Title = "Issue 10237",
            };
            plotModel.Series.Add(new LineSeries { Title = "LineSeries 1" });
            plotModel.Series.Add(new LineSeries { Title = "LineSeries 2" });
            plotModel.Series.Add(new LineSeries { Title = "LineSeries 3" });
            plotModel.IsLegendVisible = true;
            plotModel.LegendPlacement = LegendPlacement.Inside;
            plotModel.LegendPosition = LegendPosition.RightMiddle;
            plotModel.LegendOrientation = LegendOrientation.Vertical;
            return plotModel;
        }
The plot shows the legend vertically on the inside/right/middle as expected.
Is this a problem related to plot updating?

Videodrome18 wrote Aug 6, 2014 at 1:50 PM

Ah, there was the trouble. It will not create a legend if all the series titles are not initialized with their construction. Thank you!