1,下载NTGraph.ocx控件,具体下载地址:www.codeproject.com/KB/miscctrl/NTGraph_ActiveX/NTGraph_bin.zip。
2,在本机注册控件:把步骤1所下载的压缩包解压到一个指定位置,然后打开VC++,在菜单栏选择tools-->Activex Test Control Container后在弹出的窗口中选择File--》register controls,接下来就是选择NTGraph.ocx所在的路径就可以完成注册。
3,当完成第二步后就应该在系统Acticex控件库里面有你所注册的控件。当你确认控件已完成注册时就可以进行下一步的操作了。否则重新注册一遍。
4,具体使用过程:
a.用MFC向导建立一个单文档或多文档视图,该视图派生自CFormView类。
b.在project--->Add to project --->compoments and controls然后选择你所需要的控件,当然这里选择NTGraph控件。
c.完成上一步骤后Visual C++ 就会为我们创建NTGraph类,而你不需要对该类再做修改,而只要跟其他系统自带的控件使用NTGraph就行了
d.接下来,你就会在资源视图的控件菜单中找到NTGraph,使用方式和Edit 或Button控件一模一样。
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.SetElementLineColor(RGB(0,255,0));
m_Graph.SetElementwidth(1);
m_Graph.SetElementLinetype(2);
// Allocate a new element: Element-2
m_Graph.AddElement();
m_Graph.SetElementLineColor(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)
//不同的i保证了在一个控件内画出NumberOfElements条独立的曲线
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ssh_2008/archive/2009/09/02/4512137.aspx