An ActiveX Control to Display Distribution Graphs | CodeGuru

An ActiveX Control to Display Distribution Graphs

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 16, 1999
2 minute read
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).

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.