How can I draw the gray area on the chart (allowed range of the signal)?
I use the Winforms and standard Microsoft System.Windows.Forms.DataVisualization
classes.
It should be the custom range, the meaning that the starting Y point could be not zero only.
The points I get online, at run time, one by one.
UPDATE:
I tried the StripLine - it's ok, but I don't know how to define the starting point in 2d. It can be set on X only or on Y only. I tried to use the second chart (Area), but it's not what I need...
UPDATE2:
Thanks to @Reza Aghaei!!!
Here the code that works great:
void drawAllowedArea(Point startPoint, Point endPoint, PaintEventArgs e)
{
var l = (float)chart1.ChartAreas[0].AxisX.ValueToPixelPosition(startPoint.X);
var t = (float)chart1.ChartAreas[0].AxisY.ValueToPixelPosition(endPoint.Y);
var r = (float)chart1.ChartAreas[0].AxisX.ValueToPixelPosition(endPoint.X);
var b = (float)chart1.ChartAreas[0].AxisY.ValueToPixelPosition(startPoint.Y);
var rect = RectangleF.FromLTRB(l, t, r, b);
using (var br = new SolidBrush(Color.FromArgb(100, Color.Blue)))
{
e.Graphics.FillRectangle(br, rect.X, rect.Y, rect.Width, rect.Height);
}
e.Graphics.DrawRectangle(Pens.Red, rect.X, rect.Y, rect.Width, rect.Height);
}
//and use this function in chart1_Paint event:
void chart1_Paint(object sender, PaintEventArgs e)
{
drawAllowedArea(new Point(20, 50000), new Point(40, 100000), e);
}
END OF UPDATE ---------------------------------------------------------
Thank you a lot!