You are here

C program draw bar chart

This program draws bar chart using c graphics. Chart is drawn using bars filled with different styles and in different colors.

C programming code

  1. #include <graphics.h>
  2. #include <conio.h>
  3.  
  4. main()
  5. {
  6.    int gd = DETECT, gm;
  7.  
  8.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  9.  
  10.    setcolor(YELLOW);
  11.    rectangle(0,30,639,450);
  12.    settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  13.    setcolor(WHITE);
  14.    outtextxy(275,0,"Bar Chart");
  15.  
  16.    setlinestyle(SOLID_LINE,0,2);
  17.  
  18.    line(100,420,100,60);
  19.    line(100,420,600,420);
  20.    line(90,70,100,60);
  21.    line(110,70,100,60);
  22.    line(590,410,600,420);
  23.    line(590,430,600,420);
  24.  
  25.    outtextxy(95,35,"Y");
  26.    outtextxy(610,405,"X");
  27.    outtextxy(85,415,"O");
  28.  
  29.    setfillstyle(LINE_FILL,BLUE);
  30.    bar(150,100,200,419);
  31.  
  32.    setfillstyle(XHATCH_FILL,RED);
  33.    bar(225,150,275,419);
  34.  
  35.    setfillstyle(WIDE_DOT_FILL,GREEN);
  36.    bar(300,200,350,419);
  37.  
  38.    setfillstyle(INTERLEAVE_FILL,MAGENTA);
  39.    bar(375,125,425,419);
  40.  
  41.    setfillstyle(HATCH_FILL,BROWN);
  42.    bar(450,175,500,419);
  43.  
  44.    getch();
  45.    return 0;
  46. }