C #. NET Program drawing, graph

Source: Internet
Author: User

Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Drawing. Imaging;
Using System. Drawing;

 

/// <Summary>
/// Summary of DrawingCurve
/// </Summary>
Public class DrawingCurve
{

Public int intXLong = 800; // The image size is long.
Public int intYLong = 600; // The image size is high.
Public int intXMultiple = 1; // zero-scale value X
Public int intYMultiple = 0; // zero-scale value Y
Public int intXMax = 12; // maximum scale (points) X
Public int intYMax = 30; // maximum scale (points) Y

Public int intLeft = 50; // left margin
Public int intRight = 120; // right margin
Public int intTop = 30; // top margin
Public int intEnd = 50; // bottom margin

Public string strXText = "Time (unit: month)"; // unit X
Public string strYText = "quantity (unit: Count)"; // unit Y
Public string strTitle = "trend chart"; // Title
Public DataTable tbData; // The data to be counted


Private int intXScale = 30; // a scale length of X
Private int intYScale = 30; // one scale height Y
// Private int intX = 0; // coordinates of point 0 X
// Private int intY = 0; // coordinate Y at 0
Public int intData = 0; // number of records

Public DrawingCurve ()
{

IntXScale = (intXLong-intLeft-intRight)/(intXMax + 1); // One Scale length X
IntYScale = (intYLong-intTop-intEnd)/(intYMax + 1); // one scale height Y

// IntX = intXLong-intLeft; // 0 point X coordinate
// IntY = intYLong-intEnd; // Y coordinate at 0
}

Public Bitmap DrawingImg ()
{

Bitmap img = new Bitmap (intXLong, intYLong); // image size
Graphics g = Graphics. FromImage (img );
G. Clear (Color. Snow );
G. DrawString (strTitle, new Font ("", 14), Brushes. Black, new Point (5, 5 ));
G. DrawLine (new Pen (Color. Black, 2), intLeft, intYLong-intEnd, intXLong-intRight, intYLong-intEnd); // draw horizontally
G. DrawLine (new Pen (Color. Black, 2), intLeft, intTop, intLeft, intYLong-intEnd); // draw a portrait

// Draw the ordinate
G. DrawString (strYText, new Font ("", 12), Brushes. Black, new Point (intLeft, intTop); // Y Unit
Point p1 = new Point (intLeft-10, intYLong-intEnd );
For (int j = 0; j <= intYMax; j ++)
{
P1.Y = intYLong-intEnd-j * intYScale;
Point pt = new Point (p1.X + 10, p1.Y );
// Draw the scale and straight line of the ordinate
G. DrawLine (Pens. Black, pt, new Point (p1.X + 15, p1.Y ));
// Draw the text description of the ordinate
G. DrawString (Convert. ToString (j + intYMultiple), new Font ("", 12), Brushes. Black, new Point (p1.X-25, p1.Y-8 ));
}

// Draw the abscissa
G. DrawString (strXText, new Font ("", 12), Brushes. Black, new Point (intXLong-intRight, intYLong-intEnd); // X Unit
Point p = new Point (intLeft, intYLong-intEnd );
For (int I = 0; I <intXMax; I ++)
{
P. X = intLeft + I * intXScale;
// Draw the abscissa scale and straight line
G. DrawLine (Pens. Black, p, new Point (p. X, p. Y-5 ));
// Draw a text description of the abscissa
G. DrawString (Convert. ToString (I + intXMultiple), new Font ("", 12), Brushes. Black, p );
}


IntData = tbData. Rows. Count;
If (intData> 0)
{
// Trend chart
For (int I = 0; I <intData-1; I ++)
{
DataRow Row1 = tbData. Rows [I];
DataRow Row2 = tbData. Rows [I + 1];
// Define the start point
Point rec = new Point (Convert. toInt32 (intLeft + (TurnNumber (Row1 [0]. toString ()-intXMultiple) * intXScale), Convert. toInt32 (intYLong-intEnd-(TurnNumber (Row1 [1]. toString ()-intYMultiple) * intYScale ));
// Define the end point
Point dec = new Point (Convert. toInt32 (intLeft + (TurnNumber (Row2 [0]. toString ()-intXMultiple) * intXScale), Convert. toInt32 (intYLong-intEnd-(TurnNumber (Row2 [1]. toString ()-intYMultiple) * intYScale ));
// Draw a trend line
G. DrawLine (new Pen (Color. Red), rec, dec );
&

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.