Asp.net Graph Program

Source: Internet
Author: User

Asp tutorial. net Graph Program
*/
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.html controls;
Using system. drawing;
Using system. drawing. drawing2d;

Public partial class _ default: system. web. ui. page
{
Protected void page_load (object sender, eventargs e)
{
This. createimage ();
}

Private void createimage ()
{
Int height = 600, width = 800;
Bitmap image = new bitmap (width, height );
Graphics = graphics. fromimage (image );
Stringformat sf = new stringformat ();
Try
{
Graphics. clear (color. white );
Font = new font ("arial", 9, fontstyle. regular );
Font font1 = new font ("", 20, fontstyle. regular );
Lineargradientbrush brush = new lineargradientbrush (new rectangle (0, 0, image. width, image. height), color. blue, color. blue, 1.2f, true );
Graphics. fillrectangle (brushes. whitesmoke, 0, 0, width, height );
Brush brush1 = new solidbrush (color. blue );
String p_str_sum = "2010-11-10 ";

Graphics. drawstring ("analysis seniority ratio", font1, brush1, new pointf (130, 30 ));

// Draw the border line of the image
Graphics. drawrectangle (new pen (color. blue), 0, 0, image. width-1, image. height-1 );
Pen mypen = new pen (brush, 1 );
// Draw a horizontal line
Int x = 100;
For (int I = 0; I <21; I ++)
{
Graphics. drawline (mypen, x, 24, x, 340 );
X = x + 20;
}
Pen mypen1 = new pen (color. blue, 2 );
Pen mypen2 = new pen (color. red, 2 );
Graphics. drawline (mypen1, x-480, 24, x-480,340 );
// Draw vertical lines
Int y= 106;
For (int I = 0; I <22; I ++)
{
Graphics. drawline (mypen, 30,y, 600, y );
Y = y + 26;
}
Graphics. drawline (mypen1, 30, y, 600, y );
// X axis
String [] n = {"0-3 months", "3 months or more", "6 months or more", "1 year", "2 years ", "3 years", "4 years", "5 years", "6 years", "7 years", "8 years", "9 years", "10 years ", "11 years", "12 years", "13 years", "14 years", "15 years", "16 years", "17 years "};
X = 35;
For (int I = 0; I <20; I ++)
{
Graphics. drawstring (n [I]. tostring (), font, brushes. red, x, 348); // you can specify the text content and output position.
X = x + 40;
}
// Y axis
String [] m = {"20", "40", "60", "80", "100", "120 ", "140 people ",
"160", "180", "200", "220", "240", "260", "280", "300 ", "320 people", "340 people ",
"360 people", "380 people", "400 people", "600 people "};
Y = 98;
For (int I = 0; I <10; I ++)
{
Graphics. drawstring (m [I]. tostring (), font, brushes. red, 10, y); // you can specify the text content and output position.
Y = y + 26;
}
Int [] count = new int [20];
String p_year = "2010-11-10 ";
// Qldataadapter myda = new sqldataadapter (p_year, sqlcon );
// Dataset myds = new dataset ();
// Myda. fill (myds );
For (int I = 0; I <20; I ++)
{

Count [I] = I;
}
Solidbrush mybrush = new solidbrush (color. red );
Point [] mypoint = new point [20];
Mypoint [0]. x = 30; mypoint [0]. y = 340-count [0];
Mypoint [1]. x = 50; mypoint [1]. y = 340-count [1];
Mypoint [2]. x = 70; mypoint [2]. y = 340-count [2];
Mypoint [2]. x = 90; mypoint [3]. y = 340-count [3];
Mypoint [4]. x = 110; mypoint [4]. y = 340-count [4];
Mypoint [5]. x = 130; mypoint [5]. y = 340-count [5];
Mypoint [6]. x = 150; mypoint [6]. y = 340-count [6];
Mypoint [7]. x = 170; mypoint [7]. y = 340-count [7];
Mypoint [8]. x = 190; mypoint [8]. y = 340-count [8];
Mypoint [9]. x = 210; mypoint [9]. y = 340-count [9];
Mypoint [10]. x = 230; mypoint [10]. y = 340-count [10];
Mypoint [11]. x = 250; mypoint [11]. y = 340-count [11];
Mypoint [12]. x = 270; mypoint [12]. y = 340-count [12];
Mypoint [13]. x = 290; mypoint [13]. y = 340-count [13];
Mypoint [14]. x = 310; mypoint [14]. y = 340-count [14];
Mypoint [15]. x = 330; mypoint [15]. y = 340-count [15];
Mypoint [16]. x = 350; mypoint [16]. y = 340-count [16];
Mypoint [17]. x = 370; mypoint [17]. y = 340-count [17];
Mypoint [18]. x = 390; mypoint [18]. y = 340-count [18];
Mypoint [19]. x = 420; mypoint [19]. y = 340-count [19];

Graphics. drawstring ("", new font ("", 15), new solidbrush (color. red), new rectangle (0,360,120,220), sf );
Graphics. drawlines (mypen2, mypoint); // draw a line
System. io. memorystream mstream = new system. io. memorystream ();
Image. save (mstream, system.drawing.imaging.imageformat.gif );
Response. clearcontent ();
Response. contenttype = "image/gif ";
Response. binarywrite (mstream. toarray ());
}
Finally
{
Graphics. dispose ();
Image. dispose ();
}
}

}

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.