65.9K
CodeProject is changing. Read more.
Home

Bar Graph Control

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.62/5 (23 votes)

Jan 27, 2004

viewsIcon

112831

downloadIcon

4142

Simple bar graph control class derived from CStatic

Introduction

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

m_Graph.SetBarColor(1,RGB(200,200,200)); 
    //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