예제 #1
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            if (PieData == null)
            {
                return;
            }

            pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            pe.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;

            RectangleF baseRect = new RectangleF((PieWidth + BoundaryWidth) / 2, (PieWidth + BoundaryWidth) / 2, Height - 1 - PieWidth - BoundaryWidth, Height - 1 - PieWidth - BoundaryWidth);

            PointF startPoint, endPoint;
            float  startAngle = 0;

            BoundaryPen = new Pen(BoundaryColor, BoundaryWidth);


            //  TO PREVENT ABSURD BEHAVIOUR WHILE ANIMATING
            if (isSum100)
            {
                //  LAST SEGMENT
                pe.Graphics.FillPie(new SolidBrush(PieData.Last().Color), BoundaryWidth / 2, BoundaryWidth / 2, Height - 1 - BoundaryWidth, Height - 1 - BoundaryWidth, 0, 360);
                pe.Graphics.DrawArc(BoundaryPen, GetOuterBoundaryRect(baseRect), 0, 360);

                if (!FillPie)
                {
                    pe.Graphics.DrawArc(BoundaryPen, GetInnerBoundaryRect(baseRect), 0, 360);
                }
            }


            //  DRAW PIE
            foreach (PieData pieData in PieData)
            {
                float sweepAngle = (pieData.Percent / 100) * animationAngle;

                if (startAngle + sweepAngle > 360)
                {
                    sweepAngle = 360 - startAngle;
                }

                pe.Graphics.FillPie(new SolidBrush(pieData.Color), BoundaryWidth / 2, BoundaryWidth / 2, Height - 1 - BoundaryWidth, Height - 1 - BoundaryWidth, startAngle, sweepAngle);

                startAngle += sweepAngle;
            }


            //  DRAW BOUNDARIES
            DrawAllBoundaries(pe.Graphics, baseRect);


            //  LAST SEGMENT INNER AND OUTER BOUNDARY CONNECTOR
            if (BoundaryWidth > 0 && !isSum100)
            {
                GetPieSegmentCornerPoints(startAngle, out startPoint, out endPoint);
                pe.Graphics.DrawLine(BoundaryPen, startPoint, endPoint);
            }


            //  MAKE CENTER WHITE
            if (!FillPie)
            {
                pe.Graphics.FillPie(Brushes.White, PieWidth + BoundaryWidth, PieWidth + BoundaryWidth, 2 * ((Height - 1) / 2 - PieWidth - BoundaryWidth), 2 * ((Height - 1) / 2 - PieWidth - BoundaryWidth), 0, 360);
            }


            DrawValuesOnPie(pe.Graphics, baseRect.Height / 2);

            DrawLegends(pe.Graphics);
        }