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
| private void showPic(float f,Brush B) { Graphics g = this.panel1.CreateGraphics(); if (TimeNum == 0.0f) { g.FillPie(B, 0, 0, this.panel1.Width, this.panel1.Height, 0, f * 360); } else { g.FillPie(B, 0, 0, this.panel1.Width, this.panel1.Height, TimeNum, f * 360); } TimeNum += f * 360; } private void Form1_Paint(object sender, PaintEventArgs e) { ht.Clear(); Conn(); Random rnd = new Random(); using (cmd = new SqlCommand("select t_Name,sum(t_Num) as Num from tb_14 group by t_Name", con)) { Graphics g2 = this.panel2.CreateGraphics(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ht.Add(dr[0],Convert.ToInt32(dr[1])); } float[] flo = new float[ht.Count]; int T = 0; foreach (DictionaryEntry de in ht) { flo[T] = Convert.ToSingle((Convert.ToDouble(de.Value) / SumNum).ToString().Substring(0, 6)); Brush Bru = new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)));
g2.DrawString(de.Key + " " + flo[T] * 100 + "%", new Font("Arial", 8, FontStyle.Regular), Bru, 7, 5 + T * 18); showPic(flo[T], Bru); T++; } } }
|