Skip to main content
Email Password   helpLost your password?

Sample Image - NTGraph_ActiveX.jpg

Introduction

This is a simple OCX control, which allows you to plot two-dimensional data. Despite the large set of controls that comes with VC++, there is no out-of-the-box control that provides a simple and straightforward 2D data visualization. The ActiveX control tutorial by Kapil Chaturvedi inspired me to write my own control, mostly because I wanted to customize the source code when needed. Over time, the functionality of the ActiveX control became more elaborate, and finally I made decision to publish what I have in hand.

What Can It Do?

The control is able to plot a large number of points and updating one or more plots on the graph with new data, replacing the old plot with the new plot. Multiple plots with individual properties such as name, line and point style, width, could be customized at runtime. At runtime, the control is capable of displaying its own property pages (double click on the control area or by invoking the ShowProperties method) and showing short help as a result of the user pressing F1 while the control has the focus. By setting the TrackMode property you should be able to switch between a different modes such as tracking cursor coordinates while moving (left mouse button pressed), zooming, XY-, X-, and Y-panning. Finally the control snapshot could be copied to the clipboard, printed, or saved as a bitmap file.

What doesn't it do?

You cannot plot 3D data, but you can use the NTGraph3D ATL/STL/OpenGL activeX control to do that :-)!

What's New?

How to test the control

You can use the ActiveX Control Test Container, and load the Test.dsm macro from the menu Tools\Macros... You can write your own routines to test the control behavior (look at Test.dsm macro)

How to use the control

To use this OCX control, embed it in an application that supports the use of OCX controls. Microsoft Visual Basic applications, Office applications and applications created with the Microsoft Developer Studio�s AppWizard can support the use of OCX controls. There are two files required to use this control. They are:

Before the ActiveX control can be used in your application, it must be registered as a COM Component in the system registry. This is a self registering control. This means that to register the control in the system registry you only need to have an application load the control and call the control�s exported function DllRegisterServer. You can use the REGSVR32 utility or have your setup program do this.

How to use the REGSVR32 utility?

Copy NTGraph.ocx to your directory and type:

regsvr32 NTGraph.ocx
regsvr32 /u NTGraph.ocx (Unregister server)

Customizing The Control

You can change the properties of this control during design time, or in run time to affect how the control will plot the data.
Use the new control property pages:

Graph Property Page

Graph Property Page

Elements Property Page

Elements Property Page

Annotations Property Page

Annotations Property Page

Cursors Property Page

Cursors Property Page

Format Property Page

Cursors Property Page

You can include the control in your project by following the standard steps for ActiveX controls:

  1. Create MFC Dialog project or MDI/SDI project with View class derived from CFormView
  2. Choose menu Project|Add To Project|Components and Controls...
  3. Open the Registered ActiveX Control gallery
  4. Choose the NTGraph Control and click Insert
  5. Visual C++ will generate the class CNTGraph
  6. Then you can define variable of the type as CNTGraph.

The control's customization options are straightforward:

// Customize Graph Properties 


m_Graph.SetBackColor (RGB(0,0,0));
m_Graph.SetAxisColor (RGB(0,255,0));
m_Graph.SetLabelColor (RGB(128,255,255));

// Control's Frame and Plot area options

m_Graph.SetFrameColor((RGB(0,0,0));
m_Graph.SetPlotAreaColor(RGB(212,222,200));

m_Graph.SetFrameStyle(2) // (1) - Flat

                         // (2) - Scope (raised frame and sunken plot area borders)

                         // (3) - 3DFrame (a bitmap frame picture)

    
m_Graph.SetGridColor(RGB(192,192,192));
m_Graph.SetShowGrid (TRUE);

m_Graph.SetCursorColor (RGB(255,0,0));
m_Graph.SetTrackMode (1);

m_Graph.SetGraphTitle("XY Plot");
m_Graph.SetXLabel ("X Axis");
m_Graph.SetYLabel("Y Axis");
m_Graph.SetRange(0.,10,-1,1.);

You don't need to call the control Invalidate() function every time you change a Graph property. The changes are automatically reflected on the control appearance.

To load the data into the control...

//

//

// Customize Graph Elements 

//

//

   // The Graph elements are dynamically allocated! 

   
   // Element 0 is allocated by default

   // Even after a call to the ClearGraph method,

   // the Element-0  is automaticaly allocated.

  
   m_Graph.SetElementLineColor(RGB(255,0,0));
   m_Graph.SetElementLinetype(0);
   m_Graph.SetElementWidth(1);

   m_Graph.SetElementPointColor(RGB(0,0,255);
   m_Graph.SetElementPointSymbol(3);
   m_Graph.SetElementSolidPoint(TRUE);
	

   // Allocate a new element: Element-1

   m_Graph.AddElement();
	   
   m_Graph.SetElementColor (RGB(0,255,0));
   m_Graph.SetElementLinewidth(1);
   m_Graph.SetElementLinetype(2);
   
   // Allocate a new element: Element-2

   m_Graph.AddElement();

   m_Graph.SetElementColor (RGB(0,0,255));
   m_Graph.SetElementLinetype(3);
   

  // Now change again the properties of Element-1

  m_Graph.SetElement(1); 
 
  m_Graph.SetElementColor (RGB(0,0,255)); 
  ...

//

// Load Data int the Graph Elements 

//



  double y;
  for (int i = 0; i < NumberOfElements; i++) 
  {
 	for (int x = 0; x < NumberOfPoints; x++) 
	{
	   y = (double)rand() / RAND_MAX * 10.0;
	   y = y / 3 + 10.0 / 2 * i + 1;
           m_Graph.PlotXY(x, y, i); 
           // or PlotY(double data, long ElementID) 

	}
  }

The same story for Visual Basic Users:

  With NTGraph1
       .PlotAreaColor = vbBlack
       .FrameStyle = Frame
       .Caption = ""
       .XLabel = ""
       .YLabel = ""
         
       .ClearGraph 'delete all elements and create a new one

       .ElementLineColor = RGB(255, 255, 0)
       .AddElement  ' Add second elements

       .ElementLineColor = vbGreen
      
       For X = 0 To 100
            Y = Sin(X / 3.15) * Rnd - 1
            .PlotY Y, 0
             Y = Cos(X / 3.15) * Rnd + 1
            .PlotXY X, Y, 1
            .SetRange 0, 100, -3, 3
        Next X
  End With

NTGraph Properties:

Methods

Tracking Mode constants

Frame Style Constants

Line style constants

Symbol style constants

Yep, that's it!

Enjoy!

Send mail to nteofilov@yahoo.de with questions or comments about this article.

History

22 Nov 2002 - v1.0 Initial release

01 Dec 2002 - v1.1

26 Jan 2003 - v2.0 (Flicker Free versiton of the control)

09 Mar 2003 - v2.1

01 Jun 2003 - v3.0 New release!

02 Aug 2003 - v4.0 Final release!

Note that since there are significant changes in the last release you should remove (first unregister and than delete) all old versions of the control from your projects! The VBA users who use the control inside of Office applications should also remove the following file NTGRAPHLib.exd in the Temp directory of your computer. This file is automatically created by the Office application and saves properties of the former created control instances. You have to delete this file before you insert the new version of the control, in order to get correctly names in the property browser.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionAbout registering activex Pin
swapnilb1
2:16 31 Jul '09  
GeneralQuestion about the license ... Pin
sayed_7
5:44 16 Jun '09  
GeneralActive X Control insert Problem Pin
supersuakii
2:18 15 Jun '09  
GeneralTotally useless... Pin
kilt
2:24 1 Jun '09  
GeneralRe: Totally useless... Pin
DavidCrow
5:20 14 Sep '09  
GeneralRe: Totally useless... Pin
Nuri Ismail
5:24 14 Sep '09  
Questionsave graph!!!! Pin
whynot123456
23:25 20 May '09  
Generalhow to make a graph real time? Pin
whynot123456
3:59 18 May '09  
Generallog plot help please! Pin
Rohit113
21:04 17 May '09  
GeneralLicense Pin
clintM
3:50 22 Apr '09  
Generalvery good Pin
leihuajun20089
0:12 8 Apr '09  
QuestionUsing .csv Data Files Pin
heron2002
0:44 20 Mar '09  
AnswerRe: Using .csv Data Files Pin
heron2002
5:22 20 Mar '09  
General3D cone Pin
dipurb
1:33 6 Feb '09  
General3D cone Pin
dipurb
1:32 6 Feb '09  
QuestionProblems to start the demo under VS2005 Pin
Dieter68
11:33 21 Jan '09  
GeneralAnnotation Problem Pin
danjswift
9:30 9 Nov '08  
AnswerRe: Annotation Problem Pin
georgeo
0:05 12 Nov '08  
GeneralRe: Annotation Problem Pin
danjswift
7:50 26 Dec '08  
GeneralThank you very much for this useful article !!! Pin
TryToFly
23:14 16 Aug '08  
QuestionLog plot and AutoRange Pin
Giova73
1:07 24 Jul '08  
QuestionRe: Log plot and AutoRange Pin
Giova73
4:23 25 Jul '08  
QuestionNeed help for VB2008 express Pin
Riccardo.Bertoli
14:13 21 Jul '08  
AnswerRe: Need help for VB2008 express Pin
zafersavas
9:47 21 Aug '09  
QuestionExtrapolate y position from the graph Pin
Member 2959929
0:25 12 Jun '08  


Last Updated 5 Aug 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009