.net framework 画2D饼图

Bitmap cBmp = new Bitmap(width,height); //创建画布宽度为471,高度为367的Bitmap实例
            Graphics cGraphic;

            Color[] cColor = { Color.Red, Color.Blue, Color.Green, Color.Gray, Color.LightCoral, Color.Gold };

            Pen cPen;
            SolidBrush cSolidBrush;
            Point[] cPoints;
            int RowNum = 6;
            int i = 0;
            int j = 0;
            int cAngle = 0;
            int tmp = 0;

            //定义圆心坐标
            int xCircleCenter = 100;
            int yCircleCenter = 100;

            cGraphic = Graphics.FromImage(cBmp);
            cGraphic.Clear(Color.Snow);    //用白色清屏 Snow     

            string temp="";
          
            for (j = 0; j < RowNum; j++)
            {

                cAngle = 60;//(int)(60 / TotalValue) * 360;   //度数 (int)ds.Tables[0].Rows[j][0]
                //cPoints = new Point[cAngle+1];
                cPoints = new Point[cAngle+1];
                //用数学公式画圆
                cPen = new Pen(cColor[j], 3);
                cSolidBrush = new SolidBrush(cColor[j]);
                for (i = tmp; i <= (tmp + cAngle); i++)
                {
                    double t = i;
                    cPoints[i - tmp] = new Point();
                    cPoints[i - tmp].X = (int)((1-System.Math.Sin(t / 180 * System.Math.PI)) * (80));
                    cPoints[i - tmp].Y = (int)((1-System.Math.Cos(t / 180 * System.Math.PI)) * (80));
                    temp += "(" + cPoints[i-tmp].X.ToString() + "," + cPoints[i - tmp].Y.ToString() + ")/n";
                   
                }
                cGraphic.DrawString(temp, new Font("Tahoma", 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(5, 5, 200, 200));
                //加入圆心坐标点
                cPoints[cAngle] = new Point();
                cPoints[cAngle].X = xCircleCenter - 20;
                cPoints[cAngle].Y = xCircleCenter - 20;

                //画扇区对应的三角形
                cPen = new Pen(cColor[j], 3);
                cGraphic.DrawPolygon(cPen, cPoints);
                cSolidBrush = new SolidBrush(cColor[j]);
                cGraphic.FillPolygon(cSolidBrush, cPoints);

                tmp = tmp + cAngle;
            }
           
            return cBmp; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值