Click here to Skip to main content
15,884,836 members
Articles / Desktop Programming / MFC

2D Graph ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.89/5 (159 votes)
5 Aug 2003MIT8 min read 1.5M   70.2K   339  
An ActiveX control for 2D data visualisation
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Developer Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>NTGraph.ocx</TITLE>
</HEAD>
<BODY>

<!-- Insert HTML here -->

<BODY BGCOLOR=WHITE LINK=#0033CC>



<FONT FACE="ARIAL, HELVETICA" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=400>
<FONT FACE="ARIAL, HELVETICA" SIZE=2 COLOR=#660033>An ActiveX control for 2D data visualisation</FONT><BR>
<FONT FACE="ARIAL, HELVETICA" SIZE=5 COLOR=#660033><B>NTGraph ActiveX Control Sample</B></FONT>
</TD>

<P>

</TD></TR>
</TABLE>
&nbsp;<BR>


<P>
To add the NTGraph control on the web page, you should use the tag <FONT SIZE=2 COLOR=#660033>OBJECT</FONT>.
The specification of the name  of object to be inserted, and the <FONT SIZE=2 COLOR=#660033>CLASSID</FONT>
for the object which identifies what kind of object it is, both appear in the opening <FONT SIZE=2 COLOR=#660033>OBJECT</FONT>
tag along with the width and the height of the control. You have to specify the  <FONT SIZE=2 COLOR=#660033>CLASSID</FONT>
between quotes as the characters <FONT SIZE=2 COLOR=#660033>CLSSID:</FONT>, followed by the hexadecimal digits for the CLSID
that appeared in the arguments to the <FONT SIZE=2 COLOR=#660033>IMPLEMENT_OLECREATE_EX</FONT> macro in <a href="NTGraphCtl.cpp">NTGraphCtl.cpp</A>.
<p>
<CENTER>
<TABLE BORDER=1>
<TR><TD>
<OBJECT ID="CNTGraphCtrl" NAME="Graph" WIDTH=500 HEIGHT=300
  classid="clsid:14f24365-6c9d-419e-8994-e7c9179ca34f"
        >
</OBJECT>
</TR>
</TABLE>
<P>

<script language="VBScript">
<!--

sub CallPlot()

  ' Customize Graph 
	Graph.CursorColor = RGB(255,0,0)

  'Set the number of elements to be plotted
  Graph.ElementCount = 4

    'Allocate space for Elements
  'Avery Element consist of 2000 number of points
  if Graph.CreateElement(2000) = false then
     MessageBox ("Error allocating graph element")
  end if


    
  Graph.ElementColor(0) = RGB(255, 0, 0)
  Graph.ElementLinewidth(0) = 1
  Graph.ElementLinetype(0) = 1

  Graph.ElementColor(1) = RGB(0, 0, 255)
  Graph.ElementLinewidth(1) = 1
  Graph.ElementLinetype(1) = 2


  Graph.ElementColor(2) = RGB(0, 255, 0)
  Graph.ElementLinewidth(2) = 1
  Graph.ElementLinetype(2) = 3


  Graph.ElementColor(3) = RGB(125, 0, 125)
  Graph.ElementLinewidth(3) = 1
  Graph.ElementLinetype(3) = 0

 
for i = 0 to 1999
   	sigma = 150
	pi = 3.14
	x0 = 1000
	x = i
	y = 600*(exp(-(((x-x0)/sigma)*((x-x0)/sigma))/2) / (sqr(2*pi)*sigma))
        
    if Graph.SetXYValue(x,y,i,0) = false then
			MsgBox ("Unable to set Element!")
	end if
    if Graph.SetXYValue(x+100,y,i,1) = false then
			MsgBox ("Unable to set Element!")
	end if
    if Graph.SetXYValue(x-100,y*0.1,i,2) = false then
			MsgBox ("Unable to set Element!")
	end if
    if Graph.SetXYValue(x+200,y*1.2,i,3) = false then
			MsgBox ("Unable to set Element!")
	end if
next

  if Graph.SetRange(0, 2000, 0, 1) then  
  end if  
   

  Graph.CursorMode=False
   
end sub

sub AutoRange
 Graph.AutoRange()
end sub
-->
</script>


<FORM method="POST">

<P>
<CENTER>
        <INPUT TYPE="BUTTON" NAME="btnZoom" VALUE="Zoom" language="VBScript" onclick="Graph.ZoomMode=TRUE">
		<INPUT TYPE="BUTTON" NAME="btnCursor" VALUE="Cursor" language="VBScript" onclick="Graph.CursorMode=TRUE">
		<INPUT TYPE="BUTTON" NAME="btnGrid" VALUE="Grid" language="VBScript" onclick="Graph.ShowGrid=TRUE">
		<INPUT TYPE="BUTTON" NAME="btnPlot" VALUE="Plot" language="VBScript" onclick="CallPlot">
		<INPUT TYPE="BUTTON" NAME="btnAuto" VALUE="Autorange" language="VBScript" onclick="Autorange">
</CENTER>


<TABLE BORDER=0 WIDTH=50 HEIGHT=60 CELLPADDING=1 CELLSPACING=1>
<TR>
        <TD><h6>X Axis</h6></td>
        <TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE="TEXT" NAME="txtXAxis" SIZE="40" VALUE="HTML X Axis"></td>
        <TD><INPUT TYPE="BUTTON" NAME="btnXLabel" VALUE="Change X Label" language="VBScript" onclick="Graph.XLabel=txtXAxis.value"></td>
</TR>
<TR>
        <TD><h6>Y Axis</h6></td>
        <TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE="TEXT" NAME="txtYAxis" SIZE="40" VALUE="HTML Y Axis"></td>
        <TD><INPUT TYPE="BUTTON" NAME="btnYLabel" VALUE="Change Y Label" language="VBScript" onclick="Graph.YLabel=txtYAxis.value"></td>
</TR>
<TD>	<h6>Title</h6></td>
        <TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE="TEXT" NAME="txtTitle" SIZE="40" VALUE="HTML Title"</td>
        <TD><INPUT TYPE="BUTTON" NAME="btnTitle" VALUE="Change Title" language="VBScript" onclick="Graph.GraphTitle=txtTitle.value"></td>
</TR>

</TABLE>
</CENTER>

									
</FORM>


</FONT>
</BODY>
</HTML>


</BODY>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions