c# 使用chart饼图显示数据,

rabbit0310 2014-07-25 09:34:38
数据库postgres,现有数据如下
age id
4 73
26 80
1 81
3 83
10 85
25 86
25 87
30 89
31 90
35 91
37 92
56 93
102 337
27 338
27 339
27 345
27 347
27 348
25 354
55 355
32 356
21 357
我想对数据进行统计,得到结果是这样的
年龄段 个数
0-20 10
20-30 5
30-40 3
应该怎么做
...全文
795 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jj_2634851401 2014-07-27
  • 打赏
  • 举报
回复
用饼图分析市场占有率 private void showPic(float f, Brush B) { Graphics g = this.panel1.CreateGraphics(); //通过panel1控件创建一个Graphics对象 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; }//CodeGo.net/ private void Form1_Paint(object sender, PaintEventArgs e) //在Paint事件中绘制窗体 { ht.Clear(); Conn(); //连接数据库 Random rnd = new Random(); //生成随机数 using (cmd = new SqlCommand("select t_Name,sum(t_Num) as Num from tb_product group by t_Name", con)) { Graphics g2 = this.panel2.CreateGraphics(); //通过panel2控件创建一个Graphics对象 SqlDataReader dr = cmd.ExecuteReader(); //创建SqlDataReader对象 while (dr.Read()) //读取数据 { ht.Add(dr[0], Convert.ToInt32(dr[1])); //将数据添加到Hashtable中 } float[] flo = new float[ht.Count]; int T = 0; foreach (DictionaryEntry de in ht) //遍历Hashtable { 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); //调用showPic方法绘制饼型图 T++; } } }
rabbit0310 2014-07-25
  • 打赏
  • 举报
回复
引用 2 楼 duanzi_peng 的回复:
你是要查询语句
恩是的
exception92 2014-07-25
  • 打赏
  • 举报
回复
你是要查询语句
rabbit0310 2014-07-25
  • 打赏
  • 举报
回复
大家 求帮助啊
sincereKCL 2014-07-25
  • 打赏
  • 举报
回复
CREATE TABLE #t(age nvarchar(50) , count nvarchar(50)) insert into #t (age) value('0-20') insert into #t (age) value('20-30') insert into #t (age) value('30-40') update a set count =(select count(age) from ageid where age>=0 and age<=20) from #t a where a.age='0-20' update a set count =(select count(age) from ageid where age>20 and age<=30)from #t a where a.age='20-30' update a set count =(select count(age) from ageid where age >30 and age<40)from #t a where a.age='30-40' select * from #t 这样分开写看的容易点
sincereKCL 2014-07-25
  • 打赏
  • 举报
回复
先写个临时表#t,表中有三个字段age1,age2,age3,然后每个字段更新,最后查询临时表

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧