使用ASP.NET畫餅狀圖

來源:互聯網
上載者: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;  
           
           //建立畫布
          objBitmap  =  new  Bitmap(400,  440);  
          objGraphics  =  Graphics.FromImage(objBitmap);  
         
          //填充背景
          objGraphics.Clear(Color.White);

           //繪製餅狀圖
          Pen p=new Pen(Color.Yellow,0);
          Rectangle rect=new Rectangle(10,10,380,380);
          objGraphics.DrawEllipse(p,rect);
         
          //填充餅狀圖
          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);
         
          //繪製文字
          FontFamily fontfml=new FontFamily(GenericFontFamilies.Serif);
          Font font=new Font(fontfml,20);
          SolidBrush brush=new SolidBrush(Color.Blue);
          objGraphics.DrawString("ASP.NET C# 繪圖樣本",font,brush,50,400);

          //輸出並儲存圖象
          objBitmap.Save(Response.OutputStream,  ImageFormat.Gif);  
          objBitmap.Save(Server.MapPath("x.jpg"),  ImageFormat.Jpeg);  
         
          //結束繪製
          objBitmap.Dispose();  
          objGraphics.Dispose();  
}  
</script>  

<html>
<head runat="server">
   <title>無標題頁</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   
   </div>
   </form>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.