ASP.Net页面生成饼图实例
本文实例讲述了ASP.Net页面生成饼图的方法。分享给大家供大家参考。具体实现方法如下:
1.生成普通饼图:
usingSystem; usingSystem.Collections.Generic; usingSystem.Drawing; usingSystem.Drawing.Imaging; usingSystem.Linq; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls;
publicpartialclassDrawing:System.Web.UI.Page { protectedvoidPage_Load(objectsender,EventArgse) { int[]data={100,200,300,460}; Color[]colors={Color.Green,Color.Blue,Color.Yellow,Color.Tomato}; Bitmapbm=newBitmap(400,400); Graphicsg=Graphics.FromImage(bm); g.Clear(Color.White); g.DrawString("饼图测试",newFont("宋体",16),Brushes.Red,newPointF(5,5)); floattotalValue=0; foreach(intiindata) { totalValue+=i; }
floatsweepAngle=0; floatstartAngle=0; intindex=0; floatx=50f; floaty=50f; floatwidth=200f; foreach(intiindata) { sweepAngle=i/totalValue*360; g.FillPie(newSolidBrush(colors[index++]),x,y,width,width,startAngle,sweepAngle); //g.DrawPie(Pens.Black,x,y,width,width,startAngle,sweepAngle);//加边线代码 startAngle+=sweepAngle; } bm.Save(Response.OutputStream,ImageFormat.Jpeg); g.Dispose(); } }