Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to create a pie chart in windows form using c# and the numerical data is coming from SQL server. Is there any one who know how to create a pie chart on windows form? I really appreciate any answer in this.
Thanks!

Mequ
Posted
Updated 1-Apr-10 8:30am
v3

There are a lot of sample available on the web. Let me Topeka that for you: C# pie chart[^]
 
Share this answer
 
C#
//for input for pie chart..
            int i1 = int.Parse(textBox1.Text);
            int i2 = int.Parse(textBox2.Text);
            int i3 = int.Parse(textBox3.Text);
            int i4 = int.Parse(textBox4.Text);

            float total = i1 + i2 + i3 + i4;
            float deg1 = (i1 / total) * 360;
            float deg2 = (i2 / total) * 360;
            float deg3 = (i3 / total) * 360;
            float deg4 = (i4 / total) * 360;

            Pen p = new Pen(Color.Black, 2);

            Graphics g = this.CreateGraphics();

            Rectangle rec = new Rectangle(textBox1.Location.X + textBox1.Size.Width + 10, 12, 150, 150);

            Brush b1 = new SolidBrush(Color.Red);
            Brush b2 = new SolidBrush(Color.Blue);
            Brush b3 = new SolidBrush(Color.Black);
            Brush b4 = new SolidBrush(Color.BlueViolet);


            g.Clear(Form1.DefaultBackColor);
            g.DrawPie(p, rec, 0, deg1);
            g.FillPie(b1, rec, 0, deg1);
            g.DrawPie(p, rec, deg1, deg2);
            g.FillPie(b2, rec, deg1, deg2);
            g.DrawPie(p, rec, deg2 + deg1, deg3);
            g.FillPie(b3, rec, deg2 + deg1, deg3);
            g.DrawPie(p, rec, deg3 + deg2 + deg1, deg4);
            g.FillPie(b4, rec, deg3 + deg2 + deg1, deg4);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900