Example #1
0
        private void Pie_Paint(object sender, PaintEventArgs e)
        {
            Draw_Title();
            e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            e.Graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Random rnd        = new Random();
            double temp_start = 0;
            double sums       = ValueX.Sum();

            string[] colorlist = new string[5];
            colorlist[0] = "#FF4472C4";
            colorlist[1] = "#FF5B9BD5";
            colorlist[2] = "#FFED7D31";
            colorlist[3] = "#FFFFC000";
            colorlist[4] = "#FFA5A5A5";
            StringFormat _SF = new StringFormat()
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Near
            };
            Font ff = new Font("Calibri", 8, FontStyle.Regular);

            int   n     = 0;
            int   lbi   = 0;
            float xstep = 3 * (Width / 10);
            int   space = Width / LableX.Count;

            foreach (int item in ValueX)
            {
                double val    = ((item / sums) * 360);
                Color  _color = ColorTranslator.FromHtml(colorlist[n]);

                e.Graphics.FillPie(new SolidBrush(_color), new Rectangle(3 * (Width / 10), 2 * (Height / 10), 4 * (Width / 10), 6 * (Height / 10)), (float)temp_start, (float)val);
                e.Graphics.DrawPie(new Pen(Color.White, 2), new Rectangle(3 * (Width / 10), 2 * (Height / 10), 4 * (Width / 10), 6 * (Height / 10)), (float)temp_start, (float)val);
                e.Graphics.DrawString(LableX[lbi], ff,
                                      new SolidBrush(_color),
                                      new Rectangle((int)xstep, 8 * (Height / 10), 4 * (Width / 10), 2 * (Height / 10))
                                      , _SF);
                xstep      += e.Graphics.MeasureString(LableX[lbi], Font).Width;
                temp_start += val; n++; lbi++;
                if (n == 5)
                {
                    n = 0;
                }
            }
        }