public static PlotModel ImageAnnotation() { var model = new PlotModel { Title = "ImageAnnotation", Subtitle = "Click the image" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 }); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 }); OxyImage image; #if UNIVERSAL var assembly = typeof(PlotModel).GetTypeInfo().Assembly; #else var assembly = Assembly.GetExecutingAssembly(); #endif using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png")) { image = new OxyImage(stream); } var ia = new ImageAnnotation { ImageSource = image, X = new PlotLength(4, PlotLengthUnit.Data), Y = new PlotLength(2, PlotLengthUnit.Data), HorizontalAlignment = HorizontalAlignment.Right }; model.Annotations.Add(ia); // Handle left mouse clicks ia.MouseDown += (s, e) => { if (e.ChangedButton != OxyMouseButton.Left) { return; } ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right; model.InvalidatePlot(false); e.Handled = true; }; return model; }
public void AddBackgroundGradient(PlotModel model, Axis xAxis, double yStart, double yEnd, OxyColor color1, OxyColor color2) { var image = GetGradientImage(color1, color2); var colorAnnotation = new ImageAnnotation { ImageSource = image, Interpolate = true, Layer = AnnotationLayer.BelowAxes, X = new PlotLength(xAxis.ActualMinimum, PlotLengthUnit.Data), Y = new PlotLength(yStart, PlotLengthUnit.Data), Width = new PlotLength(xAxis.ActualMaximum - xAxis.ActualMinimum, PlotLengthUnit.Data), Height = new PlotLength(Math.Abs(yEnd - yStart), PlotLengthUnit.Data), HorizontalAlignment = OxyPlot.HorizontalAlignment.Left, VerticalAlignment = OxyPlot.VerticalAlignment.Bottom }; model.Annotations.Add(colorAnnotation); }
public static PlotModel ImageAnnotation() { var model = new PlotModel("ImageAnnotation", "Click the image"); model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -20, 20)); model.Axes.Add(new LinearAxis(AxisPosition.Left, -10, 10)); OxyImage image; var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png")) { image = new OxyImage(stream); } var ia = new ImageAnnotation(image, new DataPoint(4, 2), HorizontalAlignment.Right); model.Annotations.Add(ia); // Handle left mouse clicks ia.MouseDown += (s, e) => { if (e.ChangedButton != OxyMouseButton.Left) { return; } ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right; model.InvalidatePlot(false); e.Handled = true; }; return model; }