You are here

C program to draw pie chart

This C program draws a pie chart showing percentage of various components drawn with different filling styles and colors.

C programming code

/* Program to draw a pie chart */

  1. #include<graphics.h>
  2. #include<conio.h>
  3.  
  4. int main()
  5. {
  6.    int gd = DETECT, gm, midx, midy;
  7.  
  8.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  9.  
  10.    setcolor(MAGENTA);
  11.    rectangle(0,40,639,450);
  12.    settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  13.    setcolor(WHITE);
  14.    outtextxy(275,10,"Pie Chart");
  15.  
  16.    midx = getmaxx()/2;
  17.    midy = getmaxy()/2;
  18.  
  19.    setfillstyle(LINE_FILL,BLUE);
  20.    pieslice(midx, midy, 0, 75, 100);
  21.    outtextxy(midx+100, midy - 75, "20.83%");
  22.  
  23.    setfillstyle(XHATCH_FILL,RED);
  24.    pieslice(midx, midy, 75, 225, 100);
  25.    outtextxy(midx-175, midy - 75, "41.67%");
  26.  
  27.    setfillstyle(WIDE_DOT_FILL,GREEN);
  28.    pieslice(midx, midy, 225, 360, 100);
  29.    outtextxy(midx+75, midy + 75, "37.50%");
  30.  
  31.    getch();
  32.    return 0;
  33. }