1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| private void ShowPic(int Sum) { using (cmd = new SqlCommand("select t_Point,sum(t_Num) from tb_manpower group by t_Point order by sum(t_Num) desc", con)) { Bitmap bmp = new Bitmap(this.panel1.Width, this.panel1.Height); Graphics g = Graphics.FromImage(bmp); cmd.Connection.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { float f = Convert.ToSingle(dr[1]) / Sum; string str = dr[0].ToString(); drowPic(g, f, str); } g.DrawLine(new Pen(Color.Black), 0, this.panel1.Height / 2, this.panel1.Width, this.panel1.Height / 2); g.DrawLine(new Pen(Color.Black), this.panel1.Width / 2, 0, this.panel1.Width / 2, this.panel1.Height); this.panel1.BackgroundImage = bmp; dr.Close(); con.Close(); } } private void drowPic(Graphics g, float f, string str) { if (ConutNum == 0) { g.FillPie(new SolidBrush(Color.Black), 0, 0, (this.panel1.Width) / 2, (this.panel1.Height - 10) / 2, 0, 360 * f);
g.DrawString(str, new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Black), (this.panel1.Width) / 2 - 70, 10); g.DrawString(Convert.ToString(f * 100).Substring(0, 5) + "%", new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Black), (this.panel1.Width) / 2 - 70, 25); floatNum = 360 * f; ConutNum += 1; } else if (Conu tNum == 1) {
g.FillPie(new SolidBrush(Color.DarkOrange), (this.panel1.Width) / 2, 0, (this.panel1.Width) / 2, (this.panel1.Height - 10) / 2, floatNum, 360 * f);
g.DrawString(str, new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.DarkOrange), (this.panel1.Width) / 2 + 10, 10); g.DrawString(Convert.ToString(f * 100).Substring(0, 5) + "%", new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.DarkOrange), (this.panel1.Width) / 2 + 10, 25); floatNum += 360 * f; ConutNum += 1; } else if (ConutNum == 2) { g.FillPie(new SolidBrush(Color.Red), 0, (this.panel1.Height - 10) / 2 + 10, (this.panel1.Width) / 2, (this.panel1.Height - 10) / 2, floatNum, 360 * f);
g.DrawString(str, new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Red), 10, (this.panel1.Height - 10) / 2 + 20); g.DrawString(Convert.ToString(f * 100).Substring(0, 5) + "%", new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Red), 10, (this.panel1.Height - 10) / 2 + 35); floatNum += 360 * f; ConutNum += 1; } else if (ConutNum == 3) { g.FillPie(new SolidBrush(Color.Blue), (this.panel1.Width) / 2 - 10, (this.panel1.Height - 10) / 2 + 10, (this.panel1.Width) / 2, (this.panel1.Height - 10) / 2, floatNum, 360 * f); g.DrawString(str, new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Blue), (this.panel1.Width) / 2 + 10, (this.panel1.Height - 10) / 2 + 20); g.DrawString(Convert.ToString(f * 100).Substring(0, 5) + "%", new Font("宋体", 10, FontStyle.Bold), new SolidBrush(Color.Blue), (this.panel1.Width) / 2 + 10, (this.panel1.Height - 10) / 2 + 35); } }
|