Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making A Graphic Pie Chart In C#

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?

like image 903
Cistoran Avatar asked Sep 29 '09 18:09

Cistoran


People also ask

Can you make graphics in C?

In C graphics, the graphics. h functions are used to draw different shapes like circles, rectangles, etc, display text(any message) in a different format (different fonts and colors). By using the functions in the header graphics. h, programs, animations, and different games can also be made.

How do you write a graphic program in C?

initgraph(&gd, &gm, "C:\\TC\\BGI"); getch(); closegraph(); return 0; } This program initializes graphics mode and then closes it after a key is pressed. To begin with we have declared two variables of int type gd and gm for graphics driver and graphics mode respectively, you can choose any other variable name as well.

What is graphics mode in C?

graphicsMode : It is a pointer to an integer that specifies the graphics mode to be used. If *gdriver is set to DETECT , then initgraph sets *gmode to the highest resolution available for the detected driver. driverDirectoryPath : It specifies the directory path where graphics driver files ( BGI files ) are located.


1 Answers

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.

like image 193
MRG Avatar answered Nov 15 '22 04:11

MRG