本篇內(nèi)容主要講解“ASP.Net頁(yè)面生成餅圖的方法”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“ASP.Net頁(yè)面生成餅圖的方法”吧!
1.生成普通餅圖:
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Drawing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] data = { 100,200,300,460};
Color[] colors={Color.Green,Color.Blue,Color.Yellow,Color.Tomato};
Bitmap bm = new Bitmap(400,400);
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.White);
g.DrawString("餅圖測(cè)試",new Font("宋體",16),Brushes.Red,new PointF(5,5));
float totalValue = 0;
foreach (int i in data)
{
totalValue += i;
}
float sweepAngle = 0;
float startAngle = 0;
int index=0;
float x = 50f;
float y = 50f;
float width = 200f;
foreach (int i in data)
{
sweepAngle=i/totalValue*360;
g.FillPie(new SolidBrush(colors[index++]),x,y,width,width,startAngle,sweepAngle);
//g.DrawPie(Pens.Black,x,y,width,width,startAngle,sweepAngle); //加邊線(xiàn)代碼
startAngle += sweepAngle;
}
bm.Save(Response.OutputStream,ImageFormat.Jpeg);
g.Dispose();
}
}
運(yùn)行效果如下圖所示:
2.如果餅圖要加邊線(xiàn),就將上面代碼中加注釋的代碼部分取消注釋?zhuān)缦麓a所示:
復(fù)制代碼 代碼如下:
g.DrawPie(Pens.Black,x,y,width,width,startAngle,sweepAngle);
運(yùn)行結(jié)果如下圖:
到此,相信大家對(duì)“ASP.Net頁(yè)面生成餅圖的方法”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!
文章題目:ASP.Net頁(yè)面生成餅圖的方法-創(chuàng)新互聯(lián)
本文地址:http://chinadenli.net/article16/dgjidg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、建站公司、網(wǎng)站收錄、面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容