Using Zedgraph to make dynamically updated statistics

Source: Internet
Author: User

Zedgraph is a very good. NET in the open source project of the statistical map, in a previous essay mentioned that, compared with some of the other statistical control, zedgraph because it is directly on the canvas, rather than generate a picture display, so the performance is better, in such as the real time trend chart of the stock market, display CPU usage and so on real-time strong application has Good performance, the method is not difficult, but because very few people write this article, but also happened in other forums to see the problem, so write the following example.

When zedgraph a line chart, all the coordinate points are kept in pointpairlist, which is the x,y coordinate when drawing lines. To make a dynamic line chart, you actually add point coordinates to the pointpairlist, and then refresh it.

The code is simple:

Random ran = new Random ();
Pointpairlist list = new Pointpairlist ();
LineItem Mycurve;

Random is used to generate the sample data, which is the y-coordinate, pointpairlist is used to store the point collection. Mycarve is the line to draw. Of course, you can't forget to add a zedgraph control to your form.

To highlight the effect, we add the following code to the form's Load event:

This.zedGraphControl1.GraphPane.Title.Text = "Dynamic Line chart";
This.zedGraphControl1.GraphPane.XAxis.Title.Text = "Time";
This.zedGraphControl1.GraphPane.YAxis.Title.Text = "Quantity";
This.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;
for (int i = 0; I <= i++)
{
Double x = (double) New Xdate (DateTime.Now.AddSeconds (100-i));
Double y = ran. Nextdouble ();
List. ADD (x, y);
}
DateTime dt = DateTime.Now;
Mycurve = ZedGraphControl1.GraphPane.AddCurve ("My Curve",
List, Color.darkgreen, symboltype.none);
This.zedGraphControl1.AxisChange ();
This.zedGraphControl1.Refresh ();

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.