安装Iocomp工业控件,用vc6.0MFC 创建名为Curve对话图项目。
如下图所示将iPlotX Control控件插入,工具栏上将显示iPlotX控件图标。
在资源视图上添加一个按钮,并将iPlotX控件拖放上去调整界面大小。
1、在CurveDlg.cppk 添加头文件。
#include “iPlotChannelX.h”
#include “iPlottoolbarx.h”
#include “iPlotaxisx.h”
2、定义全局变量x1,在按钮事件中添加代码。
int x1;
void CCurveDlg::OnButton1()
{
// TODO: Add your control notification handler code here
SetTimer(1,1000,NULL);
x1=0;
}
3、给iPlotX控件添加变量m_iPlotX。
4、在定时器消息函数中添加代码。
void CCurveDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
if (nIDEvent ==1 && x1<=100)
{
double YRandom;//随机数
YRandom = rand()%100; // Generate Random data
m_iPlotX.GetChannel(0).AddXY(x1, YRandom );
x1=x1+1;
}
else KillTimer(1);
}
运行程序点击生成曲线按钮会动态生成曲线图如下。
免积分源码下载