How to draw rectangle over a plot?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 09:01:54

问题


Is it possible to draw rectangle using OxyPlot? Something like

:

or does OxyPlot not support this?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/29780154/how-to-draw-rectangle-over-a-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!