views:

835

answers:

6

I'm trying to write a Windows Application that shows a pie chart with seven unequal slices (25%, 20%, 18%, 17%, 10%, 10%, 10%) all of them will be colored differently.

So far I have made Pens and Brushes with colors attached and drawn a circle.

This is what I have so far

private void Form1_Paint(object sender, PaintEventArgs e)
    {
        this.BackColor = Color.White;
        this.Text = "Pie Chart";
        this.Width = 350;
        this.Height = 350;

        Pen black = new Pen(Color.Black);
        Pen blue = new Pen(Color.Blue);
        Pen green = new Pen(Color.Green);
        Pen red = new Pen(Color.Red);
        Pen orange = new Pen(Color.Orange);
        Pen pink = new Pen(Color.Pink);
        Pen purple = new Pen(Color.Purple);
        Pen magenta = new Pen(Color.Purple);
        Brush brBlue = blue.Brush;
        Brush brGreen = green.Brush;
        Brush brRed = red.Brush;
        Brush brOrange = orange.Brush;
        Brush brPink = pink.Brush;
        Brush brPurple = purple.Brush;
        Brush brMagenta = magenta.Brush;
        Graphics g = e.Graphics;

        g.DrawEllipse(black, 20, 10, 300, 300);

    }

My question to you is. What would be the easiest way to draw the wedges of the pie?

+4  A: 

This isn't a direct answer to you question, but why aren't you using the Microsoft chart controls?

Scott Gu's post about it

y0mbo
Because I don't have administrative rights on this computer to install them :)
Cistoran
You don't need to install them. Just copy the DLLs and reference them in your project.
Igor Brejc
+4  A: 

I will advise you to take a look at ZedGraph.

If you want a sample code to actually draw pieChart using GDI you can check this tutorial.. It uses FillPie Method of Graphics class.

Mahin
Thanks for this. I used fill pie and got it done.
Cistoran
@Cistoran : You are welcome. Please consider accepting answer that helped you most.
Mahin
At first I couldn't find the button. But now it is done :)
Cistoran
A: 

the easiest way would be to use an existing library ;-)

like this

Steven A. Lowe
+2  A: 

CodeProject.com has several samples. Here's one I've used. Also, I would recommend looking into the Google Chart API. It will do this for you.

David
+2  A: 

This tutorial may be helpful.

kgiannakakis
Thanks man.This was really helpful. FOLKS HERE IS THE BEST ANSEWR!!!
TheMachineCharmer
A: 

You really put 110% into this one!

Serinus