GraphLite control

GraphLite control

This article was submitted .

So much to do; so little time.
There is quite a number of controls I am planning to do, but with so precious little time to do them in. Bah, deadlines...

Some time ago, a site-visitor asked me about Graph controls in WTL, and I had to refer to the scores of professional reporting components available (as ActiveX controls).
Now that I finally needed a graph control myself, I found that the professional controls are expensive and overkill for what I'm trying to achieve. Though the company I work for will eventually purchase a professional reporting component, I decided to look for an alternative in the mean time. Fortunately there are other people on this planet who write computer programs, and some of them put their code on the web as well. So I stumbled over a nice little Visual Basic sample, which exactly covered the functionality I needed. I never - ever - had the thought of converting a VB sample before, but this is the result.

The original sample was developed by Sam Huggill and can be seen at the link below. It displays both Bar and Line charts, has axis with flexible tick markers and even displays a legend bar.

How it works

The GraphLite control is a subclassed window.

To use it, place a static control (label) on your dialog.
Add a member variable to your dialog implementation file...

CGraphCtrl m_graph
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)

The initialization phase is rather long and complex. The sample included with the code should clear things up. But essentially you add data to the control and it displays it.
One thing to remember is that the parent owns the data the control displays! That is, you create objects and arrays of values and feed them to the control. You must however not destroy this data as long as they are needed by the control.

The control uses floating points internally, which does increase the size of your app a bit and also prevents the ability of doing an _ATL_MIN_CRT compile.


The original VB sample is actually implemented as an OCX. People looking for an ActiveX version may have a closer look at that. But of course, now you will have the entire VB Runtime environment as a dependency.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 3.1 Library

See Also

My (ultra light) Pie control.

Useful Links

Sam Huggill's VB sample

Download Files

DownloadSource Code (23 Kb)

To the top