Click here to Skip to main content
12,299,663 members (51,823 online)
Click here to Skip to main content
Add your own
alternative version


272 bookmarked

3D Graph ActiveX Control

, 2 Aug 2003 MIT
Rate this:
Please Sign up or sign in to vote.
An ATL/STL ActiveX control based on OpenGL library for 3D data visualization
<!--P>You can take a look on live demo.

NTGraph3D -Sample Image

<STYLE> <!-- { list-style-image: url(NTGraph3D_ATL/prop.gif) } li.method { list-style-image: url(NTGraph3D_ATL/gmethod.gif) } --> </STYLE>


This is an ActiveX control based on the OpenGL library, which allows you to plot three-dimensional data. The control is entirely written on ATL/STL, and does not link to MFC libraries.

The control can perform the following functions:

  • Axis customization, including customizable font, colors, and titles.
  • 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.
  • Plot the multiple elements with individual properties such as line and point color, line width, and point size.
  • Lighting
  • Plot styles: {0 (Lines); 1 (Points); 2 (LinePoint); 3 (Surface)}
  • By setting the Projection property you should be able to change the viewing to: (0) Perspective (in which objects that are closer appear larger), and (1) Orthographic (in which the sizes and angles between objects are maintained no matter what their distance from the viewer).
  • By setting the TrackMode property you should be able to do: (1) Zooming, (2) Rotation, and (3) Panning at runtime.

About the Code

To use this control, embed it in an application that supports the use of ActiveX controls. Microsoft Visual Basic applications, all MS Office applications, VBScript and JavaScript in the HTA or Internet Explorer applications, and applications created with the Microsoft Developer Studio’s AppWizard can support the use of ActiveX controls.

Before you start, the control must be register as a COM component using Regsvr32.exe. Regsvr32 takes one argument the DLL or control to register and any of several command-line switches, the most notable of which is /u to uninstall a control. By default that is, when run with only a dll or ocx Regsvr32.exe registers the control.

Note: you must do this on every computer that you are going to use the control!

For more information on how to register and how to include the control in a VC Project, refer to my article 2D Graph ActiveX Control.

Bellow are two listings that demonstrates how to use the control to draw a Torus:


// Plot Torus
void CDemoDlg::OnButton1() 
   m_Graph3D.SetCaption ("Torus");
   m_Graph3D.ClearGraph(); // Clear all data
   m_Graph3D.AddElement(); // Add an element to element list

   m_Graph3D.SetElementLineColor(0, RGB(255,0,0));
   m_Graph3D.SetElementType(0, 3); // draw surface
   double x,y,z,ti,tj;
   for (int i = 0; i < 41; i++)
      ti = (i - 20.0)/20.0 * 3.15;
      for (int j = 0; j < 41 ; j++) 
	   tj = (j - 20.0)/20.0 * 3.15;
	   x = (cos(tj) + 3.0) * cos(ti);
	   y = sin(tj);
	   z = (cos(tj) + 3.0) * sin(ti);


   //m_Graph3D.SetRange (-4, 4, -1, 1, -4, 4);

Visual Basic

' Look at the Demo3D.hta file 
' Double click on file to start the demo
' Plot Torus
Sub Torus

   With Graph3D
        .Caption = "Torus"
	.ElementType(0) = 3 'Draw Surface

   For i = 0 To 41
    ti = (i - 20.0)/20.0 * 3.15

    For j = 0 To 41 
	tj = (j - 20.0)/20.0 * 3.15

	x = (cos(tj) + 3.0) * cos(ti)
	y = sin(tj)
	z = (cos(tj) + 3.0) * sin(ti)
	.PlotXYZ x,y,z,0
  End With
End Sub

List of Control Properties:


  •  short Appearance
  •  long BorderStyle
  •  VARIANT_BOOL BorderVisible
  •  BSTR Caption
  •  IFontDisp* Font
  •  OLE_COLOR BackColor
  •  OLE_COLOR CaptionColor
  •  short TrackMode
  •  short Projection
  •  BSTR XLabel
  •  BSTR YLabel
  •  BSTR ZLabel
  •  short XGridNumber
  •  short YGridNumber
  •  short ZGridNumber
  •  OLE_COLOR XGridColor
  •  OLE_COLOR YGridColor
  •  OLE_COLOR ZGridColor


  •  OLE_COLOR ElementLineColor(long ElementID, OLE_COLOR newVal)
  •  OLE_COLOR ElementPointColor(long ElementID, OLE_COLOR newVal)
  •  float ElementLineWidth(long ElementID, float newVal)
  •  float ElementPointSize(long ElementID, float newVal)
  •  short ElementType(long ElementID)
  •  BOOL ElementShow(long ElementID)
  •  BOOL ElementSurfaceFill(long ElementID)
  •  BOOL ElementSurfaceFlat(long ElementID)
  •  BOOL ElementLight(long ElementID
  •  short ElementLightingAmbient(long ElementID)
  •  short ElementLightingDiffuse(long ElementID)
  •  short ElementLightingSpecular(long ElementID)
  •  short ElementMaterialAmbient(long ElementID)
  •  short ElementMaterialDiffuse(long ElementID)
  •  short ElementMaterialSpecular(long ElementID)
  •  short ElementMaterialShinines(long ElementID)
  •  short ElementMaterialShinines(long ElementID)
  •  short ElementMaterialEmission(long ElementID)

List of Control Methods:


  •  void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
  •  void AutoRange()
  •  void ShowPropertyPages()


  •  void AddElement()
  •  void DeleteElement(long ElementID)
  •  void ClearGraph()
  •  void PlotXYZ(double x, double y, double z, long ElementID)
  •  void SetLightCoordinates(long ElementID, float x, float y, float z)

Cost: One bottle wine. Smile | :)


Note: I am not expert on OpenGL, therefore all good suggestions, code and help for imporving the control are welcome!

Send mail to with questions or comments about this article.


16 Jun 2003 - v1.0 Initial release

22 Jun 2003 - v2.0

  • Thanks to Alexander Chernosvitov for the Excellent article Function graphics in 3D.
  • Lot’s of new properties (see property list and demo files)
  • ElementType = {0 (Lines); 1 (Points); 2 (LinePoint); 3 (Surface)}
  • Added new demo file that demonstrate the new features
  • New Property BOOL ElementShow(long ElementID)
29 Jul 2003 - v2.1
  • Some drawing fixes
  • Added CopyToClipboard (Works only with release versions of the control! )
  • Added Klein Bottle
  • Changes to the Demo Projects


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Nikolai Teofilov
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
John Smith 12312314-Feb-14 6:06
memberJohn Smith 12312314-Feb-14 6:06 
QuestionLline color rainbow Pin
mahcyp27-Nov-11 7:07
membermahcyp27-Nov-11 7:07 
AnswerRe: Lline color rainbow Pin
zhaojianzhong12-Aug-12 22:55
memberzhaojianzhong12-Aug-12 22:55 
GeneralMy vote of 2 Pin
ibyk3015-Jun-11 14:25
memberibyk3015-Jun-11 14:25 
GeneralRe: My vote of 2 Pin
xrg_soft@163.com28-Jun-11 23:28
memberxrg_soft@163.com28-Jun-11 23:28 
GeneralRe: My vote of 2 Pin
elha5818-Oct-11 22:18
memberelha5818-Oct-11 22:18 
Questionsetting element color Pin
ibyk3030-May-11 7:02
memberibyk3030-May-11 7:02 
GeneralMy vote of 5 Pin
RedDK15-Apr-11 8:39
memberRedDK15-Apr-11 8:39 
Questionvisual studio 2010 ? Pin
roboticEDAR29-Mar-11 10:45
memberroboticEDAR29-Mar-11 10:45 
QuestionIs the src project is supposed to generate an ActiveX control ? Pin
Michael B Pliam31-Jan-11 11:47
memberMichael B Pliam31-Jan-11 11:47 
AnswerRe: Is the src project is supposed to generate an ActiveX control ? Pin
Michael B Pliam26-Feb-11 9:01
memberMichael B Pliam26-Feb-11 9:01 
I apologize for my ignorance concerning ATL ActiveX controls. I have discovered that my above post is completely in error. In fact, MSDN provides a detailed walk-through on how to create such an ActiveX control.


Once certain corrections are made in the NTGraph3D_src program, the code will compile using Visual Studio 2008. Further, the Custom Build Event to register the dll will work (Vista requires run as admistrator).
Once the dll is registered, the Demo3D will run but the 'torus' selection causes a runtime error related to some vector subscript boundary error. Similarly, the Torus demo will compile but encounters an immediate runtime error, likely for the same vector boundary reason.

I want to thank Ido Ben-Ami for restimulating my interest in this topic. With his help, I was able to correct the NTGraph3D_src to produce a workable dll.

For those interested, I am posting the corrections here:
Corrections made in GraphCtl.cpp
void CGraphCtl::PlotElement()
 { //..
               //if (PtInRange(aPoint))
               if (PtInRange(&*aPoint))
                   //CPoint3D pt = Corrdinate(aPoint);
                   CPoint3D pt = Corrdinate(&*aPoint);
               //if (PtInRange(aPoint))
               if (PtInRange(&*aPoint))
                   //CPoint3D pt = Corrdinate(aPoint);
                   CPoint3D pt = Corrdinate(&*aPoint);
               //int i, npt = sqrt(theElement->m_PointList.size());
               int i=0;
               int npt = int(sqrt((double)(theElement->m_PointList.size())) +0.5);
- stdafx.h
   glaux.h is not necessary and is considered obsolete
    // Add native C++ compiler COM support - BSTR, VARIANT wrappers header
   #include <comutil.h>
   //#pragma comment(lib, "comsupp.lib")
   #pragma comment(lib, "comsuppw.lib")
Hope this helps others.
QuestionWould be nice if this were NOT an ActiveX Control ? Pin
Michael B Pliam30-Jan-11 20:34
memberMichael B Pliam30-Jan-11 20:34 
AnswerRe: Would be nice if this were NOT an ActiveX Control ? Pin
nguyenvanhauk510-Jul-12 20:41
membernguyenvanhauk510-Jul-12 20:41 
GeneralUsing this library in C++ Pin
Vi_Ter5-Oct-09 4:40
memberVi_Ter5-Oct-09 4:40 
Generalgetting errors for data types(error: C2664) Pin
hituhoney16-Jul-09 2:16
memberhituhoney16-Jul-09 2:16 
GeneralRe: getting errors for data types(error: C2664) Pin
Member 389846914-Nov-09 4:52
memberMember 389846914-Nov-09 4:52 
GeneralOpen GL Pin
Myron Langer16-Apr-09 6:32
memberMyron Langer16-Apr-09 6:32 
GeneralRe: Open GL Pin
ibyk301-Jun-11 5:05
memberibyk301-Jun-11 5:05 
GeneralRe: Open GL Pin
ibyk301-Jun-11 5:26
memberibyk301-Jun-11 5:26 
GeneralUsing this library in С# Pin
getbraine20-Feb-09 23:42
membergetbraine20-Feb-09 23:42 
GeneralRe: Using this library in С# Pin
maslbl425-Aug-10 4:51
membermaslbl425-Aug-10 4:51 
GeneralRe: Using this library in С# Pin
roboticEDAR29-Mar-11 10:34
memberroboticEDAR29-Mar-11 10:34 
GeneralNTGraph3D in Access Pin
mbojanks27-Oct-08 2:43
membermbojanks27-Oct-08 2:43 
Generalntgraph Pin
abhinav bhorkar16-Oct-08 3:51
memberabhinav bhorkar16-Oct-08 3:51 
GeneralCompile Error in Excel Pin
Bonnie Douglas14-Oct-08 20:42
memberBonnie Douglas14-Oct-08 20:42 
GeneralDirect3D [modified] Pin
Raheel Anwar3-Sep-08 7:38
memberRaheel Anwar3-Sep-08 7:38 
Question3D-Graph Drawing Pin
Raheel Anwar12-Jul-08 9:51
memberRaheel Anwar12-Jul-08 9:51 
GeneralSurface Plot Not Working Pin
rob10011-Jul-08 23:41
memberrob10011-Jul-08 23:41 
GeneralRe: Surface Plot Not Working Pin
LarsLiden17-Feb-09 15:00
memberLarsLiden17-Feb-09 15:00 
GeneralRe: Surface Plot Not Working [modified] Pin
rob100111-Mar-09 17:39
memberrob100111-Mar-09 17:39 
Generalprinting Pin
danandu21-Apr-08 2:48
memberdanandu21-Apr-08 2:48 
QuestionHow to use NTGraph3D in c#? Pin
xiachunmin28-Nov-07 2:32
memberxiachunmin28-Nov-07 2:32 
AnswerRe: How to use NTGraph3D in c#? Pin
roboticEDAR29-Mar-11 10:34
memberroboticEDAR29-Mar-11 10:34 
Questionupdate surface faster Pin
Olaf Petersen25-Oct-07 3:36
memberOlaf Petersen25-Oct-07 3:36 
Generalplease help me soon Pin
kian_beh16-Oct-07 1:56
memberkian_beh16-Oct-07 1:56 
QuestionDoes any changes needed to use NTGraph3D in VISTA [modified] Pin
Sai Ravi16-Jul-07 23:00
memberSai Ravi16-Jul-07 23:00 
QuestionRe: Does any changes needed to use NTGraph3D in VISTA Pin
Sai Ravi15-Aug-07 19:01
memberSai Ravi15-Aug-07 19:01 
AnswerRe: Does any changes needed to use NTGraph3D in VISTA Pin
rob100111-Mar-09 17:45
memberrob100111-Mar-09 17:45 
GeneralElements not appearing Pin
grandmasterphat1-Apr-07 16:49
membergrandmasterphat1-Apr-07 16:49 
Generalonly plotting corners Pin
op46645-Mar-07 13:36
memberop46645-Mar-07 13:36 
GeneralNTGraph3D in Access Pin
bakerjw2-Jan-07 9:14
memberbakerjw2-Jan-07 9:14 
Generalneed draw arc member function Pin
howard200625-Aug-06 7:42
memberhoward200625-Aug-06 7:42 
QuestionUsing this Code to Draw Surface Drawing Pin
NMGajjar16-Jul-06 19:53
memberNMGajjar16-Jul-06 19:53 
QuestionCANNOT compile using VSNET2003! Pin
RedDK26-Jun-06 18:39
memberRedDK26-Jun-06 18:39 
AnswerRe: CANNOT compile using VSNET2003! Pin
hytleung21-May-07 22:25
memberhytleung21-May-07 22:25 
GeneralRe: CANNOT compile using VSNET2003! ... dereferencing ... cool Pin
RedDK15-Apr-11 8:25
memberRedDK15-Apr-11 8:25 
QuestionThis control in C# Pin
buzzy845-Jun-06 22:29
memberbuzzy845-Jun-06 22:29 
AnswerRe: This control in C# Pin
LarsLiden17-Feb-09 15:02
memberLarsLiden17-Feb-09 15:02 
GeneralRe: This control in C# Pin
vakulsr22-Apr-09 3:55
membervakulsr22-Apr-09 3:55 
GeneralProperty Pages Pin
Jairo Alonso12-Mar-06 21:51
memberJairo Alonso12-Mar-06 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 3 Aug 2003
Article Copyright 2003 by Nikolai Teofilov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid