C # Drawing graphs

Source: Internet
Author: User

C # drawing diagram ideas: Because the drawing is in the upper left corner as the starting point, so the curve is drawn after the right is the opposite direction

1. Draw a graph (rotate to a positive direction after the drawing is finished)

2. Draw a background grid

3. Merging layers

 response.clear (); Load test data datatable tbl = new DataTable (); Tbl. Columns.Add ("Price"); Tbl. Columns.Add ("Count"); Random ran = new Random (); DataRow row = null; int count = 0; int price = 0; for (int i = 0; i < i++) {row = tbl. NewRow (); row["Price" = ran. Next (0, 250); Count = ran. Next (0, 800); if (I!= 0) {if (Count < Convert.ToInt32 (TBL). rows[i-1]["Count"]) {i--; continue}} row["Count" = count; Tbl. Rows.Add (row); int width = 800; int height = 270; Picture curve Bitmap bmp = new Bitmap (width, height); Pen pen = new Pen (color.black); Graphics Grap = graphics.fromimage (BMP); Point[] points = new point[tbl. Rows.Count]; int _x; int _y; curvilinear coordinate array for (int i = 0; i < tbl. Rows.Count; i++) {int. TryParse (TBL. rows[i]["Price"]. ToString (), out _x); Int. TryParse (TBL. rows[i]["Count"]. ToString (), out _y); Points[i] = new Point (_y, _x); } grap. DrawLines (pen, points); Draw a curve bmp. RotateFlip (ROTATEFLIPTYPE.ROTATE180FLIPX); Reverse picture//Draw background pen PENBG = new Pen (color.black, 1); Bitmap BMPBG = new Bitmap (width, height); Graphics GRAPBG = Graphics.fromimage (BMPBG); Draw the horizontal for (int j = 0, i = 5; I >= 0; I--, j + +) {int var = i *; grapbg. DrawString (Convert.ToString (J *), New Font ("XXFarEastFont-Arial"), Brushes.black, New PointF (var-3)); GRAPBG. DrawLine (PENBG, new point (= Var), new Point (Var)); ///Draw longitudinal for (int j = 0, i = 0; i < 8; i++, J + +) {int var = i * +; GRAPBG. DrawLine (PENBG, New Point (Var, 0), New Point (Var, 250)); if (j = = 0) {continue} GRAPBG. DrawString (Convert.ToString (J *), New Font ("XXFarEastFont-Arial",), Brushes.black, New PointF (VAR-10, 250)); ///Merge layer GRAPBG. DrawImage (BMP, New Point (45,-19)); Save to storage stream System.IO.MemoryStream ms = new System.IO.MemoryStream (); BMPBG. Save (MS, System.Drawing.Imaging.ImageFormat.Png); Output content Response.OutputStream.Write (Ms. GetBuffer (), 0, (int) Ms. Length); Response.End ();

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.