C Program to Draw Pie Chart Using C Graphics

In this program, we will generate a pie chart on the screen with the center in the middle and a radius of 120 pixels. The outtextxy and pieslice() methods from the graphics.the h header file will be used. The comprehensive explanations of the graphics functions used in this application are provided below.

C Program to Draw Pie Chart Using C Graphics

1. Concepts

You need to have knowledge of the following concepts in order to write the C Program to Draw Pie Chart Using C Graphics.

  • initgraph
  • getmaxx
  • getmaxy
  • outtextxy
  • pieslice
  • setfillstyle
  • closegraph

void pieslice(int xCenter, int yCenter, int startAngle, int endAngle, int radius);

After learning these concepts you’re good to go.

2. C Program to Draw Pie Chart Using C Graphics

#include<graphics.h>
#include<conio.h>
  
int main() {
   int gd = DETECT, gm, x, y;
   initgraph(&gd, &gm, "C:\\TC\\BGI");
  
   settextstyle(BOLD_FONT,HORIZ_DIR,2);
   outtextxy(220,10,"PIE CHART");
   x = getmaxx()/2;
   y = getmaxy()/2;
  
   settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
   setfillstyle(SOLID_FILL, RED);
   pieslice(x, y, 0, 60, 120);
   outtextxy(x + 140, y - 70, "FOOD");
  
   setfillstyle(SOLID_FILL, YELLOW);
   pieslice(x, y, 60, 160, 120);
   outtextxy(x - 30, y - 170, "RENT");
  
   setfillstyle(SOLID_FILL, GREEN);
   pieslice(x, y, 160, 220, 120);
   outtextxy(x - 250, y, "ELECTRICITY");
  
   setfillstyle(SOLID_FILL, BROWN);
   pieslice(x, y, 220, 360, 120);
   outtextxy(x, y + 150, "SAVINGS");
  
   getch();
   closegraph();
   return 0;
}

3. Output

C Program to Draw Pie Chart Using C Graphics

4. Resources

groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *