An ActiveX Control to Display Distribution Graphs

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Environment: VC6 SP3, NT4 SP3

This ActiveX control is intended to display a distribution graph of numerical datas.
The datas are split among a set of constant intervals. The horizontal axis displays the
interval values. The vertical axis shows the number of occurences (percentage) of
numerical datas in each interval.

Each data is combined with a date. When the user clicks on one of the vertical bars, a
small windows displays all the couples (value,date) bounded be the interval.

The user of the control is allowed to specify :

  • either the interval value either the number of intervals (these two values are related),
  • a display unit (unity, thousand or million),
  • the background color,
  • the vertical bars color

There is little chance this control meets your need. But it can help you if you have
something similar to do.

The source project contains two ATL objects :

  • the control itself (CDistributionGraph)
  • a simple ATL object used to store historical datas (CHistoricalDatas)

HistoricalDatas contains the following methods and properties :

AddEntry( DATE date, double value) Add a couple (date,value) in the historic
long     Length Return number of datas
double Value(long index ) Get value at specified index
DATE Date(long index )  Get date at specified index

DistributionGraph contains the following methods and properties :

HistoricalDatas Set/Get the historical datas
double Interval Set/Get the interval value
long IntervalCount Set/Get the number of intervals
Units DisplayUnits Set/Get the display unit (One,Thousand or Million)

The two demo project (VB and VC++) show how to populate the control. The VC++ project
contains two wrapper classes (CHistoricalDatas and CDistributionGraph) which have been
generated by ClassWizard using Project|Add to Project|Components and control

Sample Visual Basic code

 

Dim hDatas As New HistoricalDatas
Dim d As Date
Dim v As Double
d = Date
For i = 0 To 200
    v = Rnd(1) * 10000
    hDatas.AddEntry DateAdd("d", i, d), v
Next i
DistributionGraph.HistoricalDatas = hDatas

Sample VC++ code

fHistoricalDatas.CreateDispatch("DGraph.HistoricalDatas.1") ;
COleDateTime date = COleDateTime::GetCurrentTime();    ;
const COleDateTimeSpan oneDay( 1, 0, 0, 0 ) ;

for ( int i = 0 ; i < 200 ; i++ )
{
	fHistoricalDatas.AddEntry( date, (10000*::rand())/RAND_MAX ) ;
	date += oneDay ;
}
fGraph.SetFillColor( RGB( 255, 0, 0 ) ) ;
fGraph.SetBackColor( ::GetSysColor( COLOR_WINDOW ) ) ;
fGraph.SetHistoricalDatas( fHistoricalDatas ) ;
fGraph.SetDisplayUnits( 0 ) ;

Downloads

Download Visual Basic demo project - 7 Kb
Download Visual C++ demo project - 17 Kb
Download source - 59 Kb

Note : Before executing demo projects, the ActiveX control
must first be registered (compile it or use regsvr32).

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read