简体   繁体   中英

How to draw rectangle over a plot?

Is it possible to draw rectangle using OxyPlot? Something like 在此处输入图片说明 :

or does OxyPlot not support this?

You can indeed.

There's a couple of ways you can do it. I would prefer to use an annotation as this will also give you a highlighted background and give you the option to add click events on this area. There's probably a way to remove the highlight if you want to make it look like the image you've provided.

var Event = new PolygonAnnotation();

Event.Layer = AnnotationLayer.BelowAxes;
Event.StrokeThickness = 5;
Event.Stroke = OxyColor.FromRgb(0, 0, 255);
Event.LineStyle = LineStyle.Automatic;

Event.Points.Add(new DataPoint(X, Y));
Event.Points.Add(new DataPoint(X, Y));            
Event.Points.Add(new DataPoint(X, Y));
Event.Points.Add(new DataPoint(X, Y));

Another more simplistic way is to create a line series and give it the corners of your rectangle.

Why not just use RectangleAnnotation which is already there? It provides fill , stroke , click detection , text. Example :

model.Annotations.Add(new RectangleAnnotation { MinimumX = 20, MaximumX = 70, MinimumY = 10, MaximumY = 40, TextRotation = 10, Text = "RectangleAnnotation", Fill = OxyColor.FromAColor(99, OxyColors.Blue), Stroke = OxyColors.Black, StrokeThickness = 2 });

You can always create your own custom annotations if existing are not good enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM