C Program to Draw 3D Bar Graph Using C Graphics

Here is a C program to draw 3D bar chart on screen using graphics.h header file. In this program, we will draw a 3D bar graph on screen. Here, we will use line, setfillstyle and bar3d functions of graphics.h header file to draw horizontal and vertical axis and bars on screen.

void line(int x1, int y1, int x2, int y2);

It draws a line from (x1, y1) to (x2, y2).

void setfillstyle(int pattern, int color);

It sets the current fill pattern and fill color.

void bar3d(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight, int depth, int topFlag);

bar3d function draws a 3D cuboid and fill front facing surface with current fill pattern and color.

Function Argument Description
xTopLeft X coordinate of top left corner.
yTopLeft Y coordinate of top left corner.
xBottomRight X coordinate of bottom right corner.
yBottomRight Y coordinate of bottom right corner.
depth It specifies the depth of bar in pixels.
topFlag It specifies whether a 3D top to put on the bar or not(any non-zero value specifies a 3d top other wise no 3d top).

C program to draw 3D bar graph using graphics

#include <graphics.h>
int main() {
   int gd = DETECT, gm;
   initgraph(&gd, &gm, "C:\\TC\\BGI");

   outtextxy(275,0,"3D BAR GRAPH");

   /* Print X and Y Axis */


   /* Print 3D bars */
   setfillstyle(XHATCH_FILL, RED);
   bar3d(150,80,200,410, 15, 1);
   bar3d(225,100,275,410, 15, 1);
   bar3d(300,120,350,410, 15, 1);
   bar3d(375,170,425,410, 15, 1);
   bar3d(450,135,500,410, 15, 1);

   return 0;
Output C graphics program to draw 3D bar graph


In wrapping up this tutorial, we've embarked on a journey to create a dynamic and visually captivating 3D bar graph using the timeless Turbo C graphics. Our exploration delved into the intricacies of setting up the Turbo C environment, the art of plotting 3D bars to represent data points, and the finesse of adding vibrant colors and labels for a more engaging visual experience. The dynamic adaptation of the graph to user input introduces a level of versatility that can cater to various datasets, making this program a versatile asset in the realm of data representation.

Beyond the lines of code, graphics programming is a canvas where mathematical precision meets artistic expression, and Turbo C remains a steadfast companion for those seeking to master these intertwined concepts. The skills acquired extend far beyond the realm of a 3D bar graph; they lay the groundwork for a deeper understanding of graphics principles applicable across diverse programming scenarios.

As we continue our journey into the captivating world of graphics programming, consider expanding this project further. Experiment with additional categories, explore novel bar styles, or infuse interactivity to bring your visualizations to life dynamically. Turbo C graphics, draped in nostalgia, imparts invaluable insights that seamlessly transcend into modern programming landscapes.

In the realm of creativity, graphics programming unfolds as a seamless dance between precision and artistic interpretation. Turbo C stands as a testament to this balance, fostering creativity and igniting the flame of curiosity for generations. Embrace the skills nurtured in this tutorial, let your creativity flow freely, and explore the boundless possibilities that graphics programming unfurls. Whether you're sculpting data, designing informative interfaces, or crafting interactive applications, Turbo C graphics provides a timeless foundation for your creative coding endeavors.

Related Topics
C Program to draw bar graph
C Program to draw a rectangle and bar
C Program to draw tangent(tan) graph
C program to draw pie chart using graphics
C graphics program to draw digital clock
C Program to draw stars in night sky on screen
C graphics program for moving car animation
List of all C Graphics Programs