Asp.net源码专业站
首页->商务办公->某市人口普查系统源码>>Code/GraphicShow.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:某市人口普查系统源码
当前文件:文件类型 RenKouPuCha/Code/GraphicShow.aspx.cs[4K,2009-6-12 11:52:57]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Drawing; 12using System.Drawing.Imaging; 13 14public partial class Code_GraphicShow : System.Web.UI.Page 15{ 16 string[] title; //列名 17 int[] rowValue; //行数据 18 int total; //总人数 19 Brush[] brush;  //填充刷子 20 Pen p = new Pen(Color.Yellow, 0); //画笔 21 Bitmap objBitmap; //画布 22 Graphics objGraphics; 23 float[] ratio; //比例 24 protected void Page_Load(object sender, EventArgs e) 25 { 26 InitialData(); 27 DrawPie(); 28 } 29 30 protected void InitialData() 31 { 32 //获取行号 33 string rowStr = Request.QueryString["row"]; 34 int row = Convert.ToInt32(rowStr); 35 36 //获取数据表 37 DataTable dt = (DataTable)Session["GeneralTable"]; 38 39 //计算表的列数 40 int colNum = dt.Columns.Count; 41 42 //获取除指标和市列以外的列标题 43 title = new string[colNum - 2]; 44 for (int i = 2; i < colNum; i++) 45 { 46 title[i - 2] = dt.Columns[i].Caption; 47 } 48 49 //获取除指标和市单元以外的行数据 50 DataRow dr = dt.Rows[row]; 51 object[] arr = dr.ItemArray; 52  rowValue= new int[colNum - 2]; 53 for (int i = 0; i < rowValue.Length; i++) 54 { 55 rowValue[i] = Convert.ToInt32(arr[i + 2]); 56 } 57 total = Convert.ToInt32(arr[1]); 58 ratio = new float[rowValue.Length]; 59 for (int i = 0; i < ratio.Length; i++) 60 { 61 ratio[i] = 360f * (float)rowValue[i] / (float)total; 62 } 63 } 64 protected void DrawPie() 65 { 66 objBitmap = new Bitmap(800, 400); 67 objGraphics = Graphics.FromImage(objBitmap); 68 objGraphics.Clear(Color.White); 69 objGraphics.DrawString("唐山市人口普查情况", new Font("宋体", 16), Brushes.Black, new PointF(5, 10)); 70 PointF symbolLeg = new PointF(335, 20); 71 PointF descLeg = new PointF(360, 16); 72 for (int i = 0; i < rowValue.Length; i++) 73 { 74 objGraphics.FillRectangle(new SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10); 75 objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10); 76 objGraphics.DrawString(title[i].ToString(), new Font("宋体", 10), Brushes.Black, descLeg); 77 symbolLeg.Y += 15; 78 descLeg.Y += 15; 79 } 80 Rectangle rect = new Rectangle(20, 50, 250, 170); 81 objGraphics.DrawEllipse(p, rect); 82 brush = new Brush[rowValue.Length]; 83 for (int i = 0; i < brush.Length; i++) 84 { 85 brush[i] = new SolidBrush(GetColor(i)); 86 } 87 float startAngle=0.0f; 88 for (int j = 0; j < rowValue.Length; j++) 89 { 90 objGraphics.FillPie(brush[j], rect, startAngle, ratio[j]); 91 startAngle += ratio[j]; 92 } 93 objBitmap.Save(Response.OutputStream, ImageFormat.Gif); 94 objBitmap.Dispose(); 95 objGraphics.Dispose(); 96 } 97 private Color GetColor(int itemIndex) 98 { 99 Color objColor = Color.Black; 100 if (itemIndex == 0) 101 { 102 objColor = Color.Blue; 103 } 104 else if (itemIndex == 1) 105 { 106 objColor = Color.Red; 107 } 108 else if (itemIndex == 2) 109 { 110 objColor = Color.Yellow; 111 } 112 else if (itemIndex == 3) 113 { 114 objColor = Color.Purple; 115 } 116 else if (itemIndex == 4) 117 { 118 objColor = Color.Orange; 119 } 120 else if (itemIndex == 5) 121 { 122 objColor = Color.Brown; 123 } 124 else if (itemIndex == 6) 125 { 126 objColor = Color.Gray; 127 } 128 else if (itemIndex == 7) 129 { 130 objColor = Color.Maroon; 131 } 132 else if (itemIndex == 8) 133 { 134 objColor = Color.Lime; 135 } 136 else if (itemIndex == 9) 137 { 138 objColor = Color.MediumOrchid; 139 } 140 else if (itemIndex == 10) 141 { 142 objColor = Color.MidnightBlue; 143 } 144 return objColor; 145 146 } 147} 148
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:某市人口普查系统源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146