简体   繁体   English

如何在地块上绘制矩形?

[英]How to draw rectangle over a plot?

Is it possible to draw rectangle using OxyPlot? 是否可以使用OxyPlot绘制矩形? Something like 就像是 在此处输入图片说明 :

or does OxyPlot not support this? 还是OxyPlot不支持此功能?

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? 为什么不只使用已经存在的RectangleAnnotation? 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. 如果现有的注释不够好,您始终可以创建自己的自定义注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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