Search code examples
c#graphplotscientific-computingoxyplot

Can Oxyplot be used in a Unit Test Library (C#)


I am creating a C# library without a User Interface, and as part of a unit test library, I would like to save these images of the graphs from the data produced in the Unit Tests. At the moment I writing the results to an excel file and producing the graphs manually, I would like the images to be saved automatically.


Solution

  • Found the answer - //Note must add a series and axis to input results...

                PlotModel model = new PlotModel() { Title = "Sample"};
                model.IsLegendVisible = true;
                model.LegendPosition = LegendPosition.RightMiddle;
                model.LegendPlacement = LegendPlacement.Outside;
                model.PlotType = PlotType.XY;     
                using (var stream = File.Create(Environment.CurrentDirectory + "/image.png"))
                {
                    OxyPlot.Wpf.PngExporter exporter = new OxyPlot.Wpf.PngExporter() { Width = 2200, Height = 1400, Resolution = 200 };
                    exporter.Export(model, stream);
                }