### Initialize PlotModel with Axes Source: https://oxyplot.readthedocs.io/en/latest/models/axes/TimeSpanAxis.html Example setup for a PlotModel with LinearAxis configurations. ```csharp var model = new PlotModel { Title = "TimeSpanAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### PieSeries Example in C# Source: https://oxyplot.readthedocs.io/en/latest/models/series/PieSeries.html Demonstrates how to create and populate a PieSeries in OxyPlot. This includes setting properties like title, stroke thickness, label position, angle span, and start angle, and adding individual PieSlice objects with labels, values, and optional explosion and color. ```csharp using OxyPlot; using OxyPlot.Series; namespace ExampleLibrary { public class PieViewModel { private PlotModel modelP1; public PieViewModel() { modelP1 = new PlotModel { Title = "Pie Sample1" }; dynamic seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 }; seriesP1.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false, Fill = OxyColors.PaleVioletRed }); seriesP1.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true }); seriesP1.Slices.Add(new PieSlice("Asia", 4157) { IsExploded = true }); seriesP1.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true }); seriesP1.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true }); modelP1.Series.Add(seriesP1); } public PlotModel Model1 { get { return modelP1; } set { modelP1 = value; } } } } ``` -------------------------------- ### Install OxyPlot.Silverlight Package Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-silverlight.html Use the Package Manager Console to install the OxyPlot.Silverlight NuGet package. ```powershell PM> Install-Package OxyPlot.Silverlight ``` -------------------------------- ### Initialize HighLowSeries PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/HighLowSeries.html Basic setup for a PlotModel using the HighLowSeries. ```csharp var model = new PlotModel { Title = "HighLowSeries" }; ``` -------------------------------- ### ContourSeries Example Source: https://oxyplot.readthedocs.io/en/latest/models/series/ContourSeries.html Demonstrates how to create and configure a ContourSeries with generated data. Ensure necessary OxyPlot namespaces are imported. ```csharp var model = new PlotModel { Title = "ContourSeries" }; double x0 = -3.1; double x1 = 3.1; double y0 = -3; double y1 = 3; //generate values Func peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y); var xx = ArrayBuilder.CreateVector(x0, x1, 100); var yy = ArrayBuilder.CreateVector(y0, y1, 100); var peaksData = ArrayBuilder.Evaluate(peaks, xx, yy); var cs = new ContourSeries { Color = OxyColors.Black, LabelBackground = OxyColors.White, ColumnCoordinates = yy, RowCoordinates = xx, Data = peaksData }; model.Series.Add(cs); ``` -------------------------------- ### Install OxyPlot.Wpf via Package Manager Console Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf-xaml.html Use this command in the Package Manager Console to install the OxyPlot.Wpf NuGet package. Ensure the Include prerelease option is active if needed. ```powershell PM> Install-Package OxyPlot.Wpf -Pre ``` -------------------------------- ### Install OxyPlot.Windows via Package Manager Console Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-uwp.html Use this command in the Package Manager Console to install the OxyPlot.Windows NuGet package. ```powershell PM> Install-Package OxyPlot.Windows ``` -------------------------------- ### LineSeries Tracker Format String Example Source: https://oxyplot.readthedocs.io/en/latest/views/tracker.html Example of a format string for LineSeries, showing X and Y values. Use this to modify the information displayed in the tracker. ```text " {0:0.00} {1:0.00} " ``` -------------------------------- ### Create and Configure ColumnSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/ColumnSeries.html Demonstrates the basic setup for a ColumnSeries, including the requirement for a CategoryAxis on the x-axis and adding a simple column item. ```csharp var model = new PlotModel { Title = "ColumnSeries" }; // A ColumnSeries requires a CategoryAxis on the x-axis. model.Axes.Add(new CategoryAxis()); var series = new ColumnSeries(); model.Series.Add(series); series.Items.Add(new ColumnItem(100)); ``` -------------------------------- ### Initialize StairStepSeries PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/StairStepSeries.html Basic setup for a PlotModel intended for use with a StairStepSeries. ```csharp var model = new PlotModel { Title = "StairStepSeries" }; ``` -------------------------------- ### Initialize TwoColorLineSeries PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/TwoColorLineSeries.html Basic setup for creating a PlotModel instance intended for use with a TwoColorLineSeries. ```csharp var model = new PlotModel { Title = "TwoColorLineSeries" }; ``` -------------------------------- ### Install OxyPlot NuGet Package Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-windows-phone.html Use the Package Manager Console to add the OxyPlot.Windows dependency to your project. ```powershell PM> Install-Package OxyPlot.Windows ``` -------------------------------- ### Create a PlotModel with LinearAxes Source: https://oxyplot.readthedocs.io/en/latest/models/axes/LinearColorAxis.html This example demonstrates how to initialize a PlotModel and add two LinearAxis objects to it, one positioned at the bottom and the other at the left. ```csharp var model = new PlotModel { Title = "LinearColorAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Initialize CandleStickSeries PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/CandleStickSeries.html Basic setup for a PlotModel intended for use with a CandleStickSeries. ```csharp var model = new PlotModel { Title = "CandleStickSeries" }; ``` -------------------------------- ### Initialize AreaSeries in PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/AreaSeries.html Basic setup for adding an AreaSeries to a PlotModel instance. ```csharp var model = new PlotModel { Title = "AreaSeries" }; var areaSeries = new AreaSeries()); ... model.Series.Add(areaSeries); ``` -------------------------------- ### HeatMapSeries with Categorized Axes (Rectangle Rendering) Source: https://oxyplot.readthedocs.io/en/latest/models/series/HeatMapSeries.html This example demonstrates using HeatMapSeries with categorized axes for both X and Y. It visualizes cake consumption per day of the week and cake type. Rectangle rendering is used, and specific axis keys are assigned. ```csharp var model = new PlotModel { Title = "Cakes per Weekday" }; // Weekday axis (horizontal) model.Axes.Add(new CategoryAxis { Position = AxisPosition.Bottom, // Key used for specifying this axis in the HeatMapSeries Key = "WeekdayAxis", // Array of Categories (see above), mapped to one of the coordinates of the 2D-data array ItemsSource = new[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } }); // Cake type axis (vertical) model.Axes.Add(new CategoryAxis { Position = AxisPosition.Left, Key = "CakeAxis", ItemsSource = new[] { "Apple cake", "Baumkuchen", "Bundt cake", "Chocolate cake", "Carrot cake" } }); // Color axis model.Axes.Add(new LinearColorAxis { Palette = OxyPalettes.Hot(200) }); var rand = new Random(); var data = new double[7, 5]; for (int x = 0; x < 5; ++x) { for (int y = 0; y < 7; ++y) { data[y, x] = rand.Next(0, 200) * (0.13 * (y + 1)); } } var heatMapSeries = new HeatMapSeries { X0 = 0, X1 = 6, Y0 = 0, Y1 = 4, XAxisKey = "WeekdayAxis", YAxisKey = "CakeAxis", RenderMethod = HeatMapRenderMethod.Rectangles, LabelFontSize = 0.2, // neccessary to display the label Data = data }; model.Series.Add(heatMapSeries); ``` -------------------------------- ### Install OxyPlot via Package Manager Console Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-windows-forms.html Use this command in the Visual Studio Package Manager Console to add the necessary dependencies. ```powershell PM> Install-Package OxyPlot.WindowsForms ``` -------------------------------- ### Initialize PlotModel for TornadoBarSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/TornadoBarSeries.html This C# code snippet demonstrates how to initialize a PlotModel with a title, which is a common setup step before adding series like TornadoBarSeries. ```csharp var model = new PlotModel { Title = "TornadoBarSeries" }; ``` -------------------------------- ### Initialize PlotModel for TwoColorAreaSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/TwoColorAreaSeries.html Use this snippet to create a basic PlotModel instance for a TwoColorAreaSeries. No specific setup is required beyond standard C#. ```csharp var model = new PlotModel { Title = "TwoColorAreaSeries" }; ``` -------------------------------- ### Initialize PlotModel for RectangleBarSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/RectangleBarSeries.html This C# code initializes a PlotModel with a title, which is a common starting point for using RectangleBarSeries. ```csharp var model = new PlotModel { Title = "RectangleBarSeries" }; ``` -------------------------------- ### Create PlotModel with Axes Source: https://oxyplot.readthedocs.io/en/latest/models/axes/RangeColorAxis.html Initializes a PlotModel and adds LinearAxis objects for the bottom and left positions with specified minimum and maximum values. This is a common setup for defining the plot area and its scales. ```csharp var model = new PlotModel { Title = "RangeColorAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Add ArrowAnnotation to PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/annotations/ArrowAnnotation.html Instantiate an ArrowAnnotation with start and end points and add it to the Annotations collection of a PlotModel. ```csharp var arrowAnnotation = new ArrowAnnotation { StartPoint = new DataPoint(0, 0), EndPoint = new DataPoint(10, 10) }; myPlotModel.Annotations.Add(arrowAnnotation); ``` -------------------------------- ### Initialize PlotModel for BoxPlotSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/BoxPlotSeries.html This C# code initializes a PlotModel with a title, which is a common starting point for creating plots, including those using BoxPlotSeries. ```csharp var model = new PlotModel { Title = "BoxPlotSeries" }; ``` -------------------------------- ### Initialize PlotModel for ErrorColumnSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/ErrorColumnSeries.html This C# code snippet demonstrates how to initialize a PlotModel with a title, which is a common setup step before adding series like ErrorColumnSeries. ```csharp var model = new PlotModel { Title = "ErrorColumnSeries" }; ``` -------------------------------- ### Initialize CategoryAxis PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/axes/CategoryAxis.html Sets up a basic PlotModel with linear axes for a CategoryAxis demonstration. ```csharp var model = new PlotModel { Title = "CategoryAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Initialize LogarithmicAxis PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/axes/LogarithmicAxis.html Sets up a basic PlotModel with LinearAxis instances for both axes. ```csharp var model = new PlotModel { Title = "LogarithmicAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Initialize IntervalBarSeries PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/series/IntervalBarSeries.html Create a basic PlotModel instance configured for an IntervalBarSeries. ```csharp var model = new PlotModel { Title = "IntervalBarSeries" }; ``` -------------------------------- ### Create a PDF file with PortableDocument Source: https://oxyplot.readthedocs.io/en/latest/extras/portable-documents.html Use the PortableDocument class to create a PDF file. The coordinate system origin is at the bottom left corner, and units are in points (1/72 inch). ```csharp var doc = new PortableDocument(); doc.Title = "Hello world"; doc.Author = "objo"; doc.AddPage(PageSize.A4); doc.SetFont("Arial", 96); doc.DrawText(50, 400, "Hello world!"); doc.Save("HelloWorld.pdf"); ``` -------------------------------- ### Configure WPF Window with PlotView Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf.html Set up the WPF Window's DataContext to the MainViewModel and include the oxy:PlotView control, binding its Model property to the ViewModel's MyModel. ```xml ``` -------------------------------- ### Initialize OxyPlot Renderers Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-xamarin-forms.html Required initialization calls for different platforms, placed after Xamarin.Forms.Forms.Init(). ```csharp OxyPlot.Xamarin.Forms.Platform.iOS.PlotViewRenderer.Init(); ``` ```csharp OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init(); ``` ```csharp OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer.Init(); ``` ```csharp OxyPlot.Xamarin.Forms.Platform.WP8.PlotViewRenderer.Init(); ``` -------------------------------- ### Create ViewModel with PlotModel and FunctionSeries Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-uwp.html Define a ViewModel that initializes a PlotModel and adds a FunctionSeries. Requires OxyPlot and OxyPlot.Series namespaces. ```csharp namespace UniversalApp1 { using System; using OxyPlot; using OxyPlot.Series; public class MainViewModel { public MainViewModel() { this.MyModel = new PlotModel { Title = "Example 1" }; this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); } public PlotModel MyModel { get; private set; } } } ``` -------------------------------- ### Create a new PlotController Source: https://oxyplot.readthedocs.io/en/latest/controllers/index.html Instantiate a new PlotController to customize input bindings. ```csharp var myController = new PlotController(); ``` -------------------------------- ### Initialize PlotModel in Windows Forms Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-windows-forms.html Create a PlotModel and assign it to a plot view within the Form constructor. ```csharp namespace WindowsFormsApplication1 { using System; using System.Windows.Forms; using OxyPlot; using OxyPlot.Series; public partial class Form1 : Form { public Form1() { this.InitializeComponent(); var myModel = new PlotModel { Title = "Example 1" }; myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); this.plot1.Model = myModel; } } } ``` -------------------------------- ### Define MainViewModel for Plotting Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-windows-phone.html Create a class that initializes a PlotModel and adds a FunctionSeries to display data. ```csharp namespace WinPhoneApp1 { using System; using OxyPlot; using OxyPlot.Series; public class MainViewModel { public MainViewModel() { this.MyModel = new PlotModel { Title = "Example 1" }; this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); } public PlotModel MyModel { get; private set; } } } ``` -------------------------------- ### Create a PlotModel with LinearAxes Source: https://oxyplot.readthedocs.io/en/latest/models/axes/MagnitudeAxis.html This C# code demonstrates how to initialize a PlotModel and add two LinearAxis objects to it, one at the bottom and one on the left, with specified minimum and maximum values. ```csharp var model = new PlotModel { Title = "MagnitudeAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Initialize AngleAxis PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/axes/AngleAxis.html Creates a PlotModel and adds LinearAxis instances to the axes collection. ```csharp var model = new PlotModel { Title = "AngleAxis" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80}); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10}); ``` -------------------------------- ### Complete Gtk# MainWindow Source Code Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-gtk.html The complete source code for a Gtk# MainWindow that includes setting up a PlotView and binding a PlotModel. Handles the delete event to quit the application. ```csharp public partial class MainWindow: Gtk.Window { public MainWindow() : base(Gtk.WindowType.Toplevel) { Build(); var plotView = new PlotView(); this.Add(plotView); plotView.ShowAll(); var myModel = new PlotModel { Title = "Example 1" }; myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); plotView.Model = myModel; } protected void OnDeleteEvent(object sender, DeleteEventArgs a) { Application.Quit(); a.RetVal = true; } } ``` -------------------------------- ### Configure XAML View Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-windows-phone.html Define the PlotView control and bind it to the DataContext in your PhoneApplicationPage. ```xml ``` -------------------------------- ### HeatMapSeries with Linear Axes (Bitmap Rendering) Source: https://oxyplot.readthedocs.io/en/latest/models/series/HeatMapSeries.html Use this snippet to display a 2D array of values as a heat map with linear axes. It requires a LinearColorAxis and generates data for a 100x100 grid. Interpolation and bitmap rendering are enabled. ```csharp var model = new PlotModel { Title = "Heatmap" }; // Color axis (the X and Y axes are generated automatically) model.Axes.Add(new LinearColorAxis { Palette = OxyPalettes.Rainbow(100) }); // generate 1d normal distribution var singleData = new double[100]; for (int x = 0; x < 100; ++x) { singleData[x] = Math.Exp((-1.0 / 2.0) * Math.Pow(((double)x - 50.0) / 20.0, 2.0)); } // generate 2d normal distribution var data = new double[100, 100]; for (int x = 0; x < 100; ++x) { for (int y = 0; y < 100; ++y) { data[y, x] = singleData[x] * singleData[(y + 30) % 100] * 100; } } var heatMapSeries = new HeatMapSeries { X0 = 0, X1 = 99, Y0 = 0, Y1 = 99, Interpolate = true, RenderMethod = HeatMapRenderMethod.Bitmap, Data = data }; model.Series.Add(heatMapSeries); ``` -------------------------------- ### Create Simple BarSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/BarSeries.html Generates a BarSeries with random data for cake popularity. Requires a List of BarItem and a CategoryAxis. The LabelFormatString is set to display percentages with two decimal places. ```csharp var model = new PlotModel{ Title = "Cake Type Popularity" }; //generate a random percentage distribution between the 5 //cake-types (see axis below) var rand = new Random(); double[] cakePopularity = new double[5]; for(int i = 0; i < 5; ++i) { cakePopularity[i] = rand.NextDouble(); } var sum = cakePopularity.Sum(); var barSeries = new BarSeries { ItemsSource = new List(new[] { new BarItem{ Value = (cakePopularity[0] / sum * 100) }, new BarItem{ Value = (cakePopularity[1] / sum * 100) }, new BarItem{ Value = (cakePopularity[2] / sum * 100) }, new BarItem{ Value = (cakePopularity[3] / sum * 100) }, new BarItem{ Value = (cakePopularity[4] / sum * 100) } }), LabelPlacement = LabelPlacement.Inside, LabelFormatString = "{0:.00}%" }; model.Series.Add(barSeries); model.Axes.Add(new CategoryAxis { Position = AxisPosition.Left, Key = "CakeAxis", ItemsSource = new[] { "Apple cake", "Baumkuchen", "Bundt Cake", "Chocolate cake", "Carrot cake" } }); ``` -------------------------------- ### Create a ScatterSeries Plot Source: https://oxyplot.readthedocs.io/en/latest/models/series/ScatterSeries.html Initializes a PlotModel with a ScatterSeries, populating it with random points and a color axis. ```csharp var model = new PlotModel { Title = "ScatterSeries" }; var scatterSeries = new ScatterSeries { MarkerType = MarkerType.Circle }; var r = new Random(314); for (int i = 0; i < 100; i++) { var x = r.NextDouble(); var y = r.NextDouble(); var size = r.Next(5, 15); var colorValue = r.Next(100, 1000); scatterSeries.Points.Add(new ScatterPoint(x, y, size, colorValue)); } model.Series.Add(scatterSeries); model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(200) }); ``` -------------------------------- ### Create WPF ViewModel with PlotModel Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf.html Define a ViewModel class that initializes a PlotModel with a FunctionSeries. This model will be bound to the PlotView control. ```csharp namespace WpfApplication1 { using System; using OxyPlot; using OxyPlot.Series; public class MainViewModel { public MainViewModel() { this.MyModel = new PlotModel { Title = "Example 1" }; this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); } public PlotModel MyModel { get; private set; } } } ``` -------------------------------- ### Plotting the Batman Curve with FunctionSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/FunctionSeries.html Demonstrates combining multiple mathematical functions into a single PlotModel to render the Batman curve. ```csharp var model = new PlotModel{ Title = "Fun with Bats" }; Func batFn1 = (x) => 2 * Math.Sqrt(-Math.Abs(Math.Abs(x) - 1) * Math.Abs(3 - Math.Abs(x)) / ((Math.Abs(x) - 1) * (3 - Math.Abs(x)))) * (1 + Math.Abs(Math.Abs(x) - 3) / (Math.Abs(x) - 3)) * Math.Sqrt(1 - Math.Pow((x / 7), 2)) + (5 + 0.97 * (Math.Abs(x - 0.5) + Math.Abs(x + 0.5)) - 3 * (Math.Abs(x - 0.75) + Math.Abs(x + 0.75))) * (1 + Math.Abs(1 - Math.Abs(x)) / (1 - Math.Abs(x))); Func batFn2 = (x) => -3 * Math.Sqrt(1 - Math.Pow((x / 7), 2)) * Math.Sqrt(Math.Abs(Math.Abs(x) - 4) / (Math.Abs(x) - 4)); Func batFn3 = (x) => Math.Abs(x / 2) - 0.0913722 * (Math.Pow(x, 2)) - 3 + Math.Sqrt(1 - Math.Pow((Math.Abs(Math.Abs(x) - 2) - 1), 2)); Func batFn4 = (x) => (2.71052 + (1.5 - .5 * Math.Abs(x)) - 1.35526 * Math.Sqrt(4 - Math.Pow((Math.Abs(x) - 1), 2))) * Math.Sqrt(Math.Abs(Math.Abs(x) - 1) / (Math.Abs(x) - 1)) + 0.9; model.Series.Add(new FunctionSeries(batFn1, -8, 8, 0.0001)); model.Series.Add(new FunctionSeries(batFn2, -8, 8, 0.0001)); model.Series.Add(new FunctionSeries(batFn3, -8, 8, 0.0001)); model.Series.Add(new FunctionSeries(batFn4, -8, 8, 0.0001)); model.Axes.Add(new LinearAxis{ Position = AxisPosition.Bottom, MaximumPadding = 0.1, MinimumPadding = 0.1 }); model.Axes.Add(new LinearAxis{ Position = AxisPosition.Left, MaximumPadding = 0.1, MinimumPadding = 0.1 }); return model; ``` -------------------------------- ### Add PlotView in C# Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-xamarin-forms.html Instantiate a PlotView within a ContentPage in the portable project. Ensure VerticalOptions and HorizontalOptions are set to avoid zero-size rendering. ```csharp public App() { this.MainPage = new ContentPage { Content = new PlotView { Model = new PlotModel { Title = "Hello, Forms!" }, VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill, }, }; } ``` -------------------------------- ### Create UWP View with PlotView Control Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-uwp.html XAML for a UWP page that sets the DataContext to MainViewModel and includes an OxyPlot PlotView. Ensure the OxyPlot.Windows namespace is referenced. ```xaml ``` -------------------------------- ### Initialize PlotView in Xamarin.Android Activity Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-xamarin-android.html This C# code demonstrates how to find the PlotView control by its ID in your Activity or Fragment and prepare it for binding a PlotModel. Make sure to include the necessary OxyPlot.Xamarin.Android namespace. ```csharp using OxyPlot.Xamarin.Android; /*...*/ PlotView view = FindViewById(Resource.Id.plot_view); ``` -------------------------------- ### Create Silverlight ViewModel with PlotModel Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-silverlight.html Define a ViewModel class that initializes a PlotModel and adds a FunctionSeries to it. This model will be bound to the PlotView. ```csharp namespace SilverlightApplication1 { using System; using OxyPlot; using OxyPlot.Series; public class MainViewModel { public MainViewModel() { this.MyModel = new PlotModel { Title = "Example 1" }; this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); } public PlotModel MyModel { get; set; } } } ``` -------------------------------- ### Create WPF Plot Model in VB.NET Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf-vb.html Define a ViewModel in VB.NET to create and configure a PlotModel with multiple LineSeries, including titles, marker types, and data points. Requires OxyPlot.Wpf NuGet package. ```vbnet Imports OxyPlot Imports OxyPlot.Series Public Class MainViewModel Private mmodel As PlotModel Public Sub New() Model = New PlotModel() Model.Title = "Simple example" Model.Subtitle = "using OxyPlot in VB.NET" Dim series1 = New LineSeries() series1.Title="Series 1" series1.MarkerType = MarkerType.Circle series1.Points.Add(New DataPoint(0, 0)) series1.Points.Add(New DataPoint(10, 18)) series1.Points.Add(New DataPoint(20, 12)) series1.Points.Add(New DataPoint(30, 8)) series1.Points.Add(New DataPoint(40, 15)) Dim series2 = New LineSeries() series2.Title="Series 2" series2.MarkerType = MarkerType.Square series2.Points.Add(New DataPoint(0, 4)) series2.Points.Add(New DataPoint(10, 12)) series2.Points.Add(New DataPoint(20, 16)) series2.Points.Add(New DataPoint(30, 25)) series2.Points.Add(New DataPoint(40, 5)) Model.Series.Add(series1) Model.Series.Add(series2) End Sub Property Model() As PlotModel Get Return mmodel End Get Set(value As PlotModel) mmodel = value End Set End Property End Class ``` -------------------------------- ### Create Grouped BarSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/BarSeries.html Creates a BarSeries with grouped data for comparison between two series. Requires CategoryAxis and LinearAxis. Legend properties are configured for outside placement at the bottom center. ```csharp var model = new PlotModel { Title = "BarSeries", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.BottomCenter, LegendOrientation = LegendOrientation.Horizontal, LegendBorderThickness = 0 }; var s1 = new BarSeries { Title = "Series 1", StrokeColor = OxyColors.Black, StrokeThickness = 1 }; s1.Items.Add(new BarItem { Value = 25 }); s1.Items.Add(new BarItem { Value = 137 }); s1.Items.Add(new BarItem { Value = 18 }); s1.Items.Add(new BarItem { Value = 40 }); var s2 = new BarSeries { Title = "Series 2", StrokeColor = OxyColors.Black, StrokeThickness = 1 }; s2.Items.Add(new BarItem { Value = 12 }); s2.Items.Add(new BarItem { Value = 14 }); s2.Items.Add(new BarItem { Value = 120 }); s2.Items.Add(new BarItem { Value = 26 }); var categoryAxis = new CategoryAxis { Position = AxisPosition.Left }; categoryAxis.Labels.Add("Category A"); categoryAxis.Labels.Add("Category B"); categoryAxis.Labels.Add("Category C"); categoryAxis.Labels.Add("Category D"); var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0 }; model.Series.Add(s1); model.Series.Add(s2); model.Axes.Add(categoryAxis); model.Axes.Add(valueAxis); ``` -------------------------------- ### MIT License Text Source: https://oxyplot.readthedocs.io/en/latest/introduction/license.html The full text of the MIT license agreement. ```plaintext The MIT License (MIT) Copyright (c) 2014 OxyPlot contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files ( the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -------------------------------- ### Copy plot to clipboard Source: https://oxyplot.readthedocs.io/en/latest/export/export-png.html Exports the plot to a bitmap and copies it to the system clipboard. Frequent calls may lead to high memory usage. ```csharp var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(plotModel); Clipboard.SetImage(bitmap); ``` -------------------------------- ### Integrate OxyPlot View in WPF XAML Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf-vb.html Define the main window XAML to set the DataContext to the MainViewModel and display the OxyPlot.PlotView, binding its Model property to the ViewModel's Model. ```xaml ``` -------------------------------- ### Add PlotView Widget in Gtk# Constructor Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-gtk.html Add the PlotView widget to the Gtk# window's constructor when using code to create the view. Ensure the widget is shown. ```csharp var plotView = new PlotView(); this.Add(plotView); plotView.ShowAll(); ``` -------------------------------- ### Exporting to PDF using OxyPlot core Source: https://oxyplot.readthedocs.io/en/latest/export/export-pdf.html Uses the PdfExporter class from the OxyPlot core library to save a plot model to a file stream. ```csharp using (var stream = File.Create(fileName)) { var pdfExporter = new PdfExporter { Width = 600, Height = 400 }; pdfExporter.Export(plotModel, stream); } ``` -------------------------------- ### Add PlotView in XAML Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-xamarin-forms.html Define the OxyPlot namespace and add the PlotView element to a XAML page. ```xml xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms" ``` ```xml ``` -------------------------------- ### Add DataPoints to LineSeries Source: https://oxyplot.readthedocs.io/en/latest/models/series/LineSeries.html Manually add data points to a LineSeries instance using the Points collection. ```csharp lineSeries1.Points.Add(new DataPoint(0, 0)); lineSeries1.Points.Add(new DataPoint(100, 40)); ``` -------------------------------- ### Export plot to a file Source: https://oxyplot.readthedocs.io/en/latest/export/export-png.html Saves the plot model directly to a file path using the PngExporter class. ```csharp var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; pngExporter.ExportToFile(plotModel, fileName); ``` -------------------------------- ### Generate StemSeries Data Source: https://oxyplot.readthedocs.io/en/latest/models/series/StemSeries.html This C# code generates data points for a sine wave and adds them to a StemSeries. Ensure OxyPlot libraries are referenced. ```csharp var model = new PlotModel{ Title = "Trigonometric functions" }; var start = -Math.PI; var end = Math.PI; var step = 0.1; int steps = (int)((Math.Abs(start) + Math.Abs(end)) / step); //generate points for functions var sinData = new DataPoint[steps]; for (int i = 0; i < steps; ++i) { var x = (start + step * i); sinData[i] = new DataPoint(x, Math.Sin(x)); } //sin(x) var sinStemSeries = new StemSeries { MarkerStroke = OxyColors.Green, MarkerType = MarkerType.Circle }; sinStemSeries.Points.AddRange(sinData); model.Series.Add(sinStemSeries); ``` -------------------------------- ### Convert DateTime to Double for DataPoints Source: https://oxyplot.readthedocs.io/en/latest/models/axes/DateTimeAxis.html Use the ToDouble method to convert DateTime values when manually adding DataPoints to a series. ```csharp mySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(myDateTime),myValue)) ``` -------------------------------- ### Silverlight View with OxyPlot PlotView Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-silverlight.html Define the XAML for the Silverlight view. Set the DataContext to the MainViewModel and include the OxyPlot PlotView control, binding its Model property to the ViewModel's MyModel. ```xaml ``` -------------------------------- ### Bind PlotModel to PlotView in Gtk# Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-gtk.html Create a PlotModel with a title and series, then assign it to the PlotView's Model property to display the plot. This is done within the constructor. ```csharp var myModel = new PlotModel { Title = "Example 1" }; myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); plotView.Model = myModel; ``` -------------------------------- ### Configure a DateTimeAxis in PlotModel Source: https://oxyplot.readthedocs.io/en/latest/models/axes/DateTimeAxis.html Create and add a DateTimeAxis to a PlotModel, specifying the axis position, range, and label format. ```csharp var model = new PlotModel { Title = "DateTimeAxis" }; var startDate = DateTime.Now.AddDays(-10); var endDate = DateTime.Now; var minValue = DateTimeAxis.ToDouble(startDate); var maxValue = DateTimeAxis.ToDouble(endDate); model.Axes.Add(new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = minValue, Maximum = maxValue, StringFormat = "M/d"}); ``` -------------------------------- ### Export plot to a stream Source: https://oxyplot.readthedocs.io/en/latest/export/export-png.html Writes the plot model to a MemoryStream using the PngExporter class. ```csharp var stream = new MemoryStream(); var pngExporter = new PngExporter { Width = 600, Height = 400, Background = OxyColors.White }; pngExporter.Export(plotModel, stream); ``` -------------------------------- ### Define WPF Plotting Data Model Source: https://oxyplot.readthedocs.io/en/latest/getting-started/hello-wpf-xaml.html Create a C# class to serve as the ViewModel for your WPF plot. This class should contain properties for the plot's title and the data points to be displayed. Ensure necessary OxyPlot namespaces are included. ```csharp namespace WpfApplication2 { using System.Collections.Generic; using OxyPlot; public class MainViewModel { public MainViewModel() { this.Title = "Example 2"; this.Points = new List { new DataPoint(0, 4), new DataPoint(10, 13), new DataPoint(20, 15), new DataPoint(30, 16), new DataPoint(40, 12), new DataPoint(50, 12) }; } public string Title { get; private set; } public IList Points { get; private set; } } } ``` -------------------------------- ### Bind a mouse down gesture to a command Source: https://oxyplot.readthedocs.io/en/latest/controllers/index.html Associate a mouse button click with a specific plot command, such as panning. ```csharp myController.BindMouseDown(OxyMouseButton.Left, PlotCommands.Pan); ``` -------------------------------- ### Set the controller in PlotView Source: https://oxyplot.readthedocs.io/en/latest/controllers/index.html Assign a custom PlotController to the PlotView control. ```csharp plotView.Controller = myController; ```