The production of real-time dynamic line chart of host computer

Source: Internet
Author: User

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;





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.