Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top