Use ASP. NET to draw a pie chart

Source: Internet
Author: User

<% @ Page contenttype = "image/GIF" %>
<% @ Import namespace = "system. Drawing" %>
<% @ Import namespace = "system. Drawing. Imaging" %>
<% @ Import namespace = "system. Drawing. Text" %>
<SCRIPT runat = "server" Language = "C #">

Void page_load (Object sender, eventargs E)
{
Bitmap objbitmap;
Graphics objgraphics;

// Create a canvas
Objbitmap = new Bitmap (400,440 );
Objgraphics = graphics. fromimage (objbitmap );

// Fill in the background
Objgraphics. Clear (color. White );

// Draw a pie chart
Pen P = new pen (color. Yellow, 0 );
Rectangle rect = new rectangle (10, 10, 380,380 );
Objgraphics. drawellipse (p, rect );

// Fill the pie chart
Brush b1 = new solidbrush (color. Red );
Brush b2 = new solidbrush (color. Green );
Brush b3 = new SolidBrush (Color. Blue );
ObjGraphics. FillPie (b1, rect, 0f, 120f );
ObjGraphics. FillPie (b2, rect, 120f, 120f );
ObjGraphics. FillPie (b3, rect, 240f, 120f );

// Draw text
FontFamily fontfml = new FontFamily (GenericFontFamilies. Serif );
Font font = new Font (fontfml, 20 );
SolidBrush brush = new SolidBrush (Color. Blue );
ObjGraphics. DrawString ("ASP. net c # drawing example", font, brush, 50,400 );

// Output and save the image
ObjBitmap. Save (Response. OutputStream, ImageFormat. Gif );
ObjBitmap. Save (Server. MapPath ("x.jpg"), ImageFormat. Jpeg );

// End the painting
ObjBitmap. Dispose ();
ObjGraphics. Dispose ();
}
</Script>

<Html>
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>

</Div>
</Form>
</Body>
</Html>

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.