解决方案 »

  1.   

    选中系列,前端设置CustomProperties="PieLabelStyle=Outside"
      

  2.   

    还要IsValueShownAsLabel="True"
      

  3.   

    饼型分析投票结果--图、表统计
     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();    }
      

  4.   

      你这是自己画的图啊,我用的chart控件,基本完成了,不想再从新自己画了谢谢
      

  5.   

      问题已经解决,是后台我只是加到集合中显示出来 ,没有具体绑定到Series1中了,修改为     ChartPie.Series["Series2"].Points.AddXY(m, zh002_002);//将累计时间和房号存储在集合中,成功了 ,多谢你!