概念:其实思路非常简单,就像画画一样,你脑中的饼图想啥样子的,就把它在网页里画出来而已。相信大家小时候都画过画,不同的是,小时候,在纸上画,现在在网页上画。 这是我脑子里饼图的样子:<激光传真机> C#后台示例代码:<激光一体机> using System; using System.Data; using System.Configuration; using System.Collections; 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.IO; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; public partial class Test : System.Web.UI.Page { // 此变量用来存储男女平均薪资的总和。 private long TotalSalary = 68228; // 此变量用来存储女性平均薪资。 private long FemaleSalary = 40690; // 此变量用来存储男性平均薪资。 private long MaleSalary = 27538; // 此变量用来存储女性空间之扇形区域之第二个边的角度。 private float sweep = 214.697784f; protected void Page_Load(object sender, EventArgs e) { //先申明个位图对象,把它当做生活中的白纸。 using (Bitmap objBitmap = new Bitmap(300, 330)) { //再申明个画图对象,准备画在位图对象里,把它当做生活中的蜡笔好了。 using (Graphics objGraphics = Graphics.FromImage(objBitmap)) { //先画个矩形大边框 Rectangle rect2 = new Rectangle(0, 0, 290, 320); objGraphics.DrawRectangle(Pens.Black, rect2); //划根线,线的上面准备画饼图,下面写个图的说明什么的。 objGraphics.DrawLine(Pens.Black, 0, 250, 290, 250); //开始画饼图,把地盘划分好。 Rectangle rect = new Rectangle(40, 10, 200, 200); objGraphics.FillPie(Brushes.Magenta, rect, 0, sweep); objGraphics.FillPie(Brushes.Blue, rect, sweep, 360 - sweep); //下面画两个方块,把饼图划的每个块说明一下 Rectangle MaleLegend = new Rectangle(5, 265, 20, 20); Rectangle FemaleLegend = new Rectangle(5, 290, 20, 20); objGraphics.FillRectangle(Brushes.Magenta, FemaleLegend); objGraphics.FillRectangle(Brushes.Blue, MaleLegend); objGraphics.DrawString("男女平均薪资的总和:", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(0, 220)); objGraphics.DrawString("男性平均薪资:", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(25, 265)); objGraphics.DrawString("女性平均薪资:", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(25, 290)); objGraphics.DrawString(TotalSalary.ToString("N") + " 元", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(180, 220)); objGraphics.DrawString(MaleSalary.ToString("N") + " 元", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(180, 265)); objGraphics.DrawString(FemaleSalary.ToString("N") + " 元", new Font("Tahoma", 10, FontStyle.Regular), Brushes.Black, new PointF(180, 290)); //然后美化一下 objGraphics.SmoothingMode = SmoothingMode.AntiAlias; objGraphics.Clear(Color.White); //最后在网页上输出。 Response.ContentType = "Image/GIF"; Response.Clear(); Response.BufferOutput = true; objBitmap.Save(Response.OutputStream, ImageFormat.Gif); } } } } 推荐链接:长宸办公