Click here to Skip to main content
13,355,292 members (62,323 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 26 Jan 2004

Bar Graph Control

, 26 Jan 2004
Rate this:
Please Sign up or sign in to vote.
Simple bar graph control class derived from CStatic


Here is a simple bar graph control class derived from CStatic. It supports displaying real-time data, using any number of bars with different colors, using scale both in cm and inch, etc.

Using the code

How to add this control to your project:

  1. Copy files GraphCtrl.h and GraphCtrl.cpp to your project directory, and add to your project.
  2. Include GraphCtrl.h in files where you need to use this class.
  3. Change CStatic definitions to CGraphCtrl.
  4. Use the API described below.
int SetNumberOfBars(int num)
//Sets the number of bars you want to display. 
//If successful, it returns number of bars set, otherwise -1.
int SetBarColor(int idx, COLORREF clr)
//Sets the color for the bars.  idx is the index of the 
//bar from left to right (1,2,3..etc.)
//If successful, it returns index of the bar for which 
//the color was set, otherwise -1.
void SetUnit(int unit)
//Sets the scale to cm or inch. Send UCM for cm and UINCH for inch
void SetBarValue(int idx, int value)
//Sets the value of a bar.  idx is the index of the bar 
//for which the value to be set and 
//the parameter value is the value we have to set for it.

Example of Use

m_Graph.SetNumberOfBars(18); //Number of bars to be shown

    //Sets the color to the bar of index 1

m_Graph.SetBarValue(1,22); //Sets value to the bar of index 1

m_Graph.SetUnit(UCM);  //Sets scale to cm


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Team Leader
India India
Mr. Shaibujan has got 9+ yrs of programming experience in C/C++, on various domains like Cryptography, Biometric Security, Network Security, Pattern Recognition, Image Processing, MPEG2, MPEG4, H.264, AAC etc.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Vinod Viswanath14-Sep-12 22:06
memberVinod Viswanath14-Sep-12 22:06 
GeneralMy vote of 2 Pin
DRLaverdure18-Sep-10 10:27
memberDRLaverdure18-Sep-10 10:27 
GeneralThere is a nice bar chart .Net component as well Pin
oklook14-Aug-09 2:40
memberoklook14-Aug-09 2:40 
Questionlarge number of bars? Pin
Jared CompEng29-Apr-07 3:14
memberJared CompEng29-Apr-07 3:14 
Questionambiguous size of bar ??!!!? Pin
mohsen nourian20-Sep-06 21:24
membermohsen nourian20-Sep-06 21:24 
GeneralSave to Bitmap File Pin
varandas7918-Jun-06 4:00
membervarandas7918-Jun-06 4:00 
Generalerror in line : using namespace std Pin
mohsen nourian24-Sep-06 3:25
membermohsen nourian24-Sep-06 3:25 
Generalproblem with big values Pin
Kostis Mentzelos4-Apr-04 13:32
memberKostis Mentzelos4-Apr-04 13:32 
GeneralRe: problem with big values Pin
mohsen nourian24-Sep-06 20:27
membermohsen nourian24-Sep-06 20:27 
GeneralSetBarColor Pin
Kostis Mentzelos4-Apr-04 4:33
memberKostis Mentzelos4-Apr-04 4:33 
GeneralRe: SetBarColor Pin
hucker14-Jun-04 12:01
memberhucker14-Jun-04 12:01 
GeneralRe: SetBarColor Pin
NiFF9-Dec-04 0:44
memberNiFF9-Dec-04 0:44 
General- Memory Leak Pin
Chaitanya1232-Mar-04 10:18
memberChaitanya1232-Mar-04 10:18 
GeneralRe: - Memory Leak Pin
Shaibujan3-Mar-04 7:07
memberShaibujan3-Mar-04 7:07 
GeneralIncorrect Device MapMode ... Pin
Behzad Ebrahimi3-Feb-04 3:49
memberBehzad Ebrahimi3-Feb-04 3:49 
GeneralRe: Incorrect Device MapMode ... Pin
Shaibujan3-Feb-04 7:21
memberShaibujan3-Feb-04 7:21 
GeneralQuestion on OnCustomDraw Pin
YoSilver27-Jan-04 16:17
memberYoSilver27-Jan-04 16:17 
GeneralRe: Question on OnCustomDraw Pin
Shaibujan28-Jan-04 7:49
memberShaibujan28-Jan-04 7:49 
GeneralFinally about time... Pin
Snyp27-Jan-04 13:00
memberSnyp27-Jan-04 13:00 
GeneralRe: Finally about time... Pin
Shaibujan27-Jan-04 20:27
memberShaibujan27-Jan-04 20:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 27 Jan 2004
Article Copyright 2004 by Shaibujan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid