Asp.net chart控件做饼图数据显示问题

luanhongtong123 2015-01-13 04:57:12
如标题,图倒是显示正常了,但是我想把每一个小扇形的数字在扇形外显示,this.ChartPie.Series["Series2"]["PieLabelStyle"] = "Outside"; 这句话就是不起作用,不知道咋回事,在里边太难看了太乱了,看图 ,请大神帮忙!
...全文
488 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luanhongtong123 2015-01-14
  • 打赏
  • 举报
回复
引用 5 楼 xiao_1724200453 的回复:
饼型分析投票结果--图、表统计 public void CreatePieImage() { //定义数据库连接字符串 string connString = System.Configuration.ConfigurationManager.AppSettings["conn"].ToString(); //建立与数据库连接的对象 SqlConnection conn = new SqlConnection(connString); //打开数据库连接 conn.Open(); //定义查询数据库的SQL语句 string cmdtxt = "select * from tb_vote"; //定义一个SqlCommand命令对象 SqlCommand comm = new SqlCommand(cmdtxt, conn); //定义一个数据集 DataSet ds = new DataSet(); //定义一个数据适配器 SqlDataAdapter da = new SqlDataAdapter(comm); //填充数据集 da.Fill(ds); conn.Close(); float Total = 0.0f, Tmp; int iLoop; for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++) { //转换成单精度,也可以写成Convert.ToInt32 Tmp = Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]); Total += Tmp; } //设置字体,fontTitle为主标题的字体 Font fontLegend = new Font("verdana",9),fontTitle = new Font("verdana",10,FontStyle.Bold); //设置背景宽 int width = 250; int bufferspase = 15; int legendheight = fontLegend.Height * (ds.Tables[0].Rows.Count + 1) + bufferspase; int titleheight = fontTitle.Height+bufferspase; //设置白色背景高 int height = width + legendheight + titleheight + bufferspase; int pieheight = width; Rectangle pierect = new Rectangle(0,titleheight,width,pieheight); //加上各种随机色 ArrayList colors = new ArrayList(); //生成伪随机生成器 Random rnd = new Random(); for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++) colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)))); //创建一个bitmap实例 Bitmap objbitmap = new Bitmap(width,height); Graphics objgraphics = Graphics.FromImage(objbitmap); //画一个白色背景 objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height); //画一个亮黄色背景 objgraphics.FillRectangle(new SolidBrush(Color.LightYellow),pierect); //以下为画饼型图(有几行row画几个) float currentdegree = 0.0f; for(iLoop = 0; iLoop<ds.Tables[0].Rows.Count;iLoop++) { objgraphics.FillPie((SolidBrush)colors[iLoop],pierect,currentdegree, Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) / Total * 360); currentdegree += Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) / Total * 360; }//codego.net/tags/11/1/ //以下生成主标题 SolidBrush blackbrush = new SolidBrush(Color.Black); string title = "明日科技图书投票调查结果"; //封闭文本局部信息 StringFormat Format = new StringFormat(); //设置垂直面上的文本信息位置居中 Format.Alignment = StringAlignment.Center; //设置水平面上的文本信息位置居中 Format.LineAlignment = StringAlignment.Center; objgraphics.DrawString(title,fontTitle,blackbrush, new Rectangle(0,0,width,titleheight),Format); //列出各字段与得数目 objgraphics.DrawRectangle(new Pen(Color.Black, 2), 0, height - legendheight, width, legendheight); for(iLoop = 0;iLoop<ds.Tables[0].Rows.Count;iLoop++) { objgraphics.FillRectangle((SolidBrush)colors[iLoop],5,height - legendheight + fontLegend.Height * iLoop+5,10,10); //读出数据库中的“图书名称”、“投票数量”信息 objgraphics.DrawString(((String)ds.Tables[0].Rows[iLoop]["图书名称"]) +"(" +(ds.Tables[0].Rows[iLoop]["投票数量"])+"票"+")"+ "——" + Convert.ToString(Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) * 100 /Total).Substring(0, 5) + "%", fontLegend, blackbrush, 20, height - legendheight + fontLegend.Height * iLoop + 1); } //图像总的高度-一行字体的高度,即是最底行的一行字体高度(height - fontLegend.Height ) objgraphics.DrawString("明日图书投票总数是:" + Convert.ToString(Total), fontLegend, blackbrush, 5, height - fontLegend.Height); //输出图片格式为gif Response.ContentType = "image/gif"; objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); objgraphics.Dispose(); objbitmap.Dispose(); }
你这是自己画的图啊,我用的chart控件,基本完成了,不想再从新自己画了。。。谢谢
xiao_1724200453 2015-01-14
  • 打赏
  • 举报
回复
饼型分析投票结果--图、表统计 public void CreatePieImage() { //定义数据库连接字符串 string connString = System.Configuration.ConfigurationManager.AppSettings["conn"].ToString(); //建立与数据库连接的对象 SqlConnection conn = new SqlConnection(connString); //打开数据库连接 conn.Open(); //定义查询数据库的SQL语句 string cmdtxt = "select * from tb_vote"; //定义一个SqlCommand命令对象 SqlCommand comm = new SqlCommand(cmdtxt, conn); //定义一个数据集 DataSet ds = new DataSet(); //定义一个数据适配器 SqlDataAdapter da = new SqlDataAdapter(comm); //填充数据集 da.Fill(ds); conn.Close(); float Total = 0.0f, Tmp; int iLoop; for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++) { //转换成单精度,也可以写成Convert.ToInt32 Tmp = Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]); Total += Tmp; } //设置字体,fontTitle为主标题的字体 Font fontLegend = new Font("verdana",9),fontTitle = new Font("verdana",10,FontStyle.Bold); //设置背景宽 int width = 250; int bufferspase = 15; int legendheight = fontLegend.Height * (ds.Tables[0].Rows.Count + 1) + bufferspase; int titleheight = fontTitle.Height+bufferspase; //设置白色背景高 int height = width + legendheight + titleheight + bufferspase; int pieheight = width; Rectangle pierect = new Rectangle(0,titleheight,width,pieheight); //加上各种随机色 ArrayList colors = new ArrayList(); //生成伪随机生成器 Random rnd = new Random(); for (iLoop = 0; iLoop < ds.Tables[0].Rows.Count; iLoop++) colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)))); //创建一个bitmap实例 Bitmap objbitmap = new Bitmap(width,height); Graphics objgraphics = Graphics.FromImage(objbitmap); //画一个白色背景 objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height); //画一个亮黄色背景 objgraphics.FillRectangle(new SolidBrush(Color.LightYellow),pierect); //以下为画饼型图(有几行row画几个) float currentdegree = 0.0f; for(iLoop = 0; iLoop<ds.Tables[0].Rows.Count;iLoop++) { objgraphics.FillPie((SolidBrush)colors[iLoop],pierect,currentdegree, Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) / Total * 360); currentdegree += Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) / Total * 360; }//codego.net/tags/11/1/ //以下生成主标题 SolidBrush blackbrush = new SolidBrush(Color.Black); string title = "明日科技图书投票调查结果"; //封闭文本局部信息 StringFormat Format = new StringFormat(); //设置垂直面上的文本信息位置居中 Format.Alignment = StringAlignment.Center; //设置水平面上的文本信息位置居中 Format.LineAlignment = StringAlignment.Center; objgraphics.DrawString(title,fontTitle,blackbrush, new Rectangle(0,0,width,titleheight),Format); //列出各字段与得数目 objgraphics.DrawRectangle(new Pen(Color.Black, 2), 0, height - legendheight, width, legendheight); for(iLoop = 0;iLoop<ds.Tables[0].Rows.Count;iLoop++) { objgraphics.FillRectangle((SolidBrush)colors[iLoop],5,height - legendheight + fontLegend.Height * iLoop+5,10,10); //读出数据库中的“图书名称”、“投票数量”信息 objgraphics.DrawString(((String)ds.Tables[0].Rows[iLoop]["图书名称"]) +"(" +(ds.Tables[0].Rows[iLoop]["投票数量"])+"票"+")"+ "——" + Convert.ToString(Convert.ToSingle(ds.Tables[0].Rows[iLoop]["投票数量"]) * 100 /Total).Substring(0, 5) + "%", fontLegend, blackbrush, 20, height - legendheight + fontLegend.Height * iLoop + 1); } //图像总的高度-一行字体的高度,即是最底行的一行字体高度(height - fontLegend.Height ) objgraphics.DrawString("明日图书投票总数是:" + Convert.ToString(Total), fontLegend, blackbrush, 5, height - fontLegend.Height); //输出图片格式为gif Response.ContentType = "image/gif"; objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); objgraphics.Dispose(); objbitmap.Dispose(); }
luanhongtong123 2015-01-14
  • 打赏
  • 举报
回复
哎呀,前端显示时正常了按你的方法,但是调试起来硬是不好用,后台写的有问题吗
Hello World, 2015-01-14
  • 打赏
  • 举报
回复
还要IsValueShownAsLabel="True"
luanhongtong123 2015-01-14
  • 打赏
  • 举报
回复
引用 1 楼 apollokk 的回复:
选中系列,前端设置CustomProperties="PieLabelStyle=Outside"
是这样用吧,还是没有作用呢,怎么回事呢,请大神帮忙,在线等。。。
luanhongtong123 2015-01-14
  • 打赏
  • 举报
回复
引用 3 楼 apollokk 的回复:
还要IsValueShownAsLabel="True"
问题已经解决,是后台我只是加到集合中显示出来 ,没有具体绑定到Series1中了,修改为 ChartPie.Series["Series2"].Points.AddXY(m, zh002_002);//将累计时间和房号存储在集合中,成功了 ,多谢你!
Hello World, 2015-01-13
  • 打赏
  • 举报
回复
选中系列,前端设置CustomProperties="PieLabelStyle=Outside"

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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