Click here to 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
GeneralProblems with managed c++
juanvo
12:05 8 Feb '10  
Hi,
This OCX do not work in managed Visual C + +. With # import does not work. Do you have any example in managed Visual C++ ?
Thank you very much.
Best regards
QuestionAbout registering activex
swapnilb1
2:16 31 Jul '09  
Dear Sir,
I downloaded your demo project But It says that activex is not register..
How can I register it???I am Using vc++6.0Confused
GeneralQuestion about the license ...
sayed_7
5:44 16 Jun '09  
Hi

This is a very good code indeed. I have used that in one of my software. My question is can I distribute it with the software and sell itConfused ?

Sayed

Trusted

GeneralActive X Control insert Problem
supersuakii
2:18 15 Jun '09  
I'm using VS2008.
I choosed the NTGraph control and click insert but Interface is _DNTGraph and class is CDNTGraph.
What's the problem?
Confused
GeneralTotally useless...
kilt
2:24 1 Jun '09  
Why reinventing the wheel ?!!!
The Microsoft Graph control exists for 16 years !
And a lot more powerful..
GeneralRe: Totally useless...
DavidCrow
5:20 14 Sep '09  
Says the person that has neither created an article nor made a useful post. Roll eyes

"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons


GeneralRe: Totally useless...
Nuri Ismail
5:24 14 Sep '09  
The article is very very useful! 5 from me! Thumbs Up

But your posts as you mention very often:
kilt
Totally useless...

... yes, your posts are totally useless! Roll eyes
GeneralRe: Horsehocky
Member 2145437
12:12 1 Dec '09  
You're not allowed to redistribute the msChart control. This means that the target system HAS to have MS Office installed :~
Questionsave graph!!!!
whynot123456
23:25 20 May '09  
how to save the graph i have drawn? Roll eyes
AnswerRe: save graph!!!!
Member 2145437
12:19 1 Dec '09  
Save the DATA for the graph in a structured file or database; then recreate the graph as needed by passing the structured filename to your app as a command parameter.

Or, save the control snapshot to the clipboard, then to a BMP file. (A highly inefficient approach from a storage viewpoint...)
Generalhow to make a graph real time?
whynot123456
3:59 18 May '09  
hi, wonderful work.it is very useful for me.

i have a question about graph that i made before,and i want to replace it whit a new graph real time,how can I do?
any help would be thankful....

Thank you.
Generallog plot help please!
Rohit113
21:04 17 May '09  
hi, very good activeX control. thank you its very useful for me.

im having problems with the log plot, When i have small values on the Y axis, such as from say
-0.005 to 0.005.Then when i convert it to log scale, the values produced on the y-axis are random and the scale is not log. how can i fix this problem?

any help would be great Smile

Thank you.
GeneralLicense
clintM
3:50 22 Apr '09  
Nikolai,

Great graph control (NTGraph)!!! My question is about licenses. I see that there are no licenses listed with the control. Can you tell me what (if any) the license restrictions on the graph control.

Thanks.

Clint
Generalvery good
leihuajun20089
0:12 8 Apr '09  
thank you!
QuestionUsing .csv Data Files
heron2002
0:44 20 Mar '09  
Hi,

This control works great, I have used it for simple graph creation so far in vb.net. My question is, is there any way you can import data from a file (such as a .csv or .xls doc)?

I've played around trying to do this for a few days now with no success.

Obviously there may be a way to seperatly open up said file and pick out the points individually and plot using .PlotXY(100, 211, 1) for example, but with 1001 data points that may be difficult, plus my coding skills are basic at best.

If you know if this is possible i'd appreciate it.

Cheers.
AnswerRe: Using .csv Data Files
heron2002
5:22 20 Mar '09  
Ok, I came up with a solution, its not pretty, it takes a few seconds to create the chart, but it works.

oApp = CreateObject("Excel.Application")
xlBook = oApp.Workbooks.Open("C:\Test Data.xlsx")

'Setup Counters
Count601 = 601
DataPoints = 0
n1 = 1

Do While DataPoints < Count601 'Inner Loop

x = xlBook.ActiveSheet.Cells.Range("A" & n1).Value
y = xlBook.ActiveSheet.Cells.Range("B" & n1).Value
AxNTGraph1.PlotXY(x, y, 1)
n1 = n1 + 1 'Increment Range Counter
DataPoints = DataPoints + 1 'Increment Loop Counter

If DataPoints = Count601 Then 'If Condition is True
Check = False 'Set Value of Flag to False
End If 'Exit Inner Loop

Loop
General3D cone
dipurb
1:33 6 Feb '09  
I wan to write a program to drawa 3D cone using VC++. The input is a sine wave. can any one help me psl....???
General3D cone
dipurb
1:32 6 Feb '09  
I wan to write a program to drawa 3D cone using VC++. The input is a sine wave. can any one help me psl....???
QuestionProblems to start the demo under VS2005
Dieter68
11:33 21 Jan '09  
Hi,

I tried to start the DlgDemo with VS2005, but I just got some assertion failures.

Another problem that I found is, that when I try to open the dialog in the "Resource View" I get the error message: 2 ActiveX controls could not be instantiated. Reinstall or register the controls and try again.

Any idea what could help?
I guess there are some ActiveX settings wrong.

Thanks
Dieter

...

GeneralAnnotation Problem
danjswift
9:30 9 Nov '08  
The graph control is great, but I have not been able to get annotations to work. I have made sure that they are checked for visible, and that the colors show up on the background. I am not sure if the coordinates refer to the ones inside the graph (I assume not; rather that they are absolute, always starting at 0,0) but in any case, I have tried a variety of coordinates and have yet to see my annotation appear.
AnswerRe: Annotation Problem
georgeo
0:05 12 Nov '08  
I only figured out the annotation a few days ago.
this is what I have in my code ( the locations x and y for the annotation are based on the graph coordinated)


//// TESTING ANNOTATION


m_ntgraph.AddAnnotation();
m_ntgraph.SetAnnoLabelBkColor(RGB(255,255,255));
m_ntgraph.SetAnnoLabelColor(RGB(255,0,0));
m_ntgraph.SetAnnotation(iblade); // THIS IS THE NUMBER OF THE ANNOTTION YOU WISH TO USE, I HAVE LOOPED IT IN A FOR STATEMENT WITH iblade BEING THE VARIABLE
m_ntgraph.SetAnnoLabelX(x_value);
m_ntgraph.SetAnnoLabelY(y_value);
m_ntgraph.SetAnnoLabelCaption(ang_txt[iblade]); // and my caption is a CString array

And if anyone has a solution to the small font on the printout I would be grateful for their help.
GeneralRe: Annotation Problem
danjswift
7:50 26 Dec '08  
Thanks for your help. It turns out that I did not realize that the SetAnnotation(} function takes a zero-based argument and that the first annotation must be identified with a value of 0.

Sorry, but I do not have a solution for the font size issue.
GeneralThank you very much for this useful article !!!
TryToFly
23:14 16 Aug '08  
Smile this article is very helpful to me,and I am very glad the author shares it free ,thank you for your help to me.
QuestionLog plot and AutoRange
Giova73
1:07 24 Jul '08  
Hi

that's a very good ActiveX Control but I have a problem with Log plot.

The AutoRange function doesn't rescale the plot in the interesting range.

I have tried to SetRange(minX,maxX,minY,maxY) but it doesn't have any effect on the curve

I'm using the YLog property checked

Is there a way to zoom in the plot automatically ?


Thanks
Giova
QuestionRe: Log plot and AutoRange
Giova73
4:23 25 Jul '08  
To continue my first message I should add that I'm writing a VC++ application with dialog boxes.

- Using the activeX, I have also noticed that clicking on the Graph it changes properties of width even if I do SetElementWidth(1)

dear Nikolai Teofilov , is it simple to correct ?

- About Log scale, the axis values are not readable in my application

Is it a bug of my implementation or someone had met this problem ?

ciao
Red faced
Giovanna


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