Example of OxyPlot.Wpf renders blank


first of all thanks for the great work, LinqPad is just awesome!

I am trying to display the default example of a WPF OxyPlot line chart with the code below, but the output remains white.
I've also tried to put it into a Grid and set the width/height, but the result didn't change.

var model = new PlotModel { Title = "Example 1" };
model.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
var plotView = new PlotView();
plotView.Model = model;

I am using LinqPad 5.44.02 (Premium Edition). Any Ideas?



  • Options
    edited February 2022

    There's some dodgy code in OxyPlot.Wpf. In PlotViewBase:

    private bool IsInVisualTree()
        DependencyObject dependencyObject = this;
        while ((dependencyObject = VisualTreeHelper.GetParent(dependencyObject)) != null)
            if (dependencyObject is Window)
                return true;
        return false;

    If the parent is not a Window, OxyPlot assumes that the control is not in a visual tree. LINQPad doesn't use a Window to host WPF controls; it uses an ElementHost.

    I suggest you run the OxyPlot.WindowsForms instead. It seems to perform quite well in LINQPad:

    var model = new PlotModel { Title = "Example 1" };
    var series = new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)");
    var plotView = new PlotView { Model = model }.Dump();
    for (int i = 0; i < 100; i++)
        await Task.Delay (10);

    Edit: it looks like this problem has been fixed in the OxyPlot.Wpf source code, but the NuGet package hasn't yet been updated. They don't seem to release too often.

  • Options

    A similar issue seems to be fixed last month for rendering within SkiaSharp:


    I will try to extend OxyPlot to check for ElementHost as well.... otherwise using WinForms is also an acceptable solution. Thanks!

  • Options

    Checking for ElementHost in IsInVisualTree seems not to work either... doesen't matter, I'll continue with the WinForms solution. Thanks again :).

Sign In or Register to comment.