问题
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