As shown in the graph, he will update the graph in real time according to the data returned, and adjust the display range dynamically.
Production method:
First place a chart control, referencing the namespace
Using System.Windows.Forms.DataVisualization.Charting;
The following is the initialization code
InitializeComponent ();
Set the style of the curve
Series Series = Chart1. Series[0];
Draw the spline curve (Spline)
series. ChartType = Seriescharttype.fastline;
Line width 2 pixel
series. BorderWidth = 2;
Color of the line: Red
series. Color = System.Drawing.Color.Red;
The text on the Diagram
series. LegendText = "Temperature";
Set the display range
ChartArea ChartArea = Chart1. Chartareas[0];
chartArea.AxisX.Minimum = 0;
ChartArea.AxisX.Maximum = ten;
ChartArea.AxisY.Minimum = -5d;
ChartArea.AxisY.Maximum = 45d;
Chart1. Chartareas[0]. AxisX.ScrollBar.IsPositionedInside = false;//refers to whether the scroll bar is in the chart area or outside the chart area
Chart1. Chartareas[0]. AxisX.ScrollBar.Enabled = true;
To achieve dynamic display, you need to set a global variable, such as Xpos, to start with a value of 0, each receiving a data, call
Series1. POINTS.ADDXY (horizontal axis, ordinate);
To increase the number of new points
Meanwhile, the horizontal axis plus 1
xpos++;
The following statement dynamically adjusts the number of points in the field of vision
Chart1. Chartareas[0]. AxisX.ScaleView.Size = xpos;