MFC中用teechart控件做了一个实时动态曲线显示的程序,程序修改前

baidu_27553761 2015-05-29 09:12:59
在以下程序中,teechart控件能随着时间动态地将数据实时的用曲线显示出来。
BOOL CCodeAddCurve_1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

m_TeeChart.Series(0).Clear();
m_TeeChart.Series(1).Clear();
m_TeeChart.Series(2).Clear();

InitChart();
SetTimer(1,1000,NULL);

return TRUE; // return TRUE unless you set the focus to a control
}
其中,InitChart();如下:
void CCodeAddCurve_1Dlg::InitChart()
{
//设置X轴与Y轴的标题:
m_TeeChart.GetAxis().GetLeft().GetTitle().SetCaption("temperature");
m_TeeChart.GetAxis().GetBottom().GetTitle().SetCaption("time");

m_TeeChart.Series(0).FillSampleValues(50); //向第一个Line序列中添加数据
m_TeeChart.Series(1).FillSampleValues(50); //向第二个Line序列中添加数据
m_TeeChart.Series(2).FillSampleValues(50); //向第二个Line序列中添加数据

m_TeeChart.Series(0).SetColor(RGB(255, 0, 0)); // 设置第一条曲线的颜色为红色
m_TeeChart.Series(1).SetColor(RGB(0, 255, 0)); //设置第二条曲线的颜色为绿色
m_TeeChart.Series(2).SetColor(RGB(0, 100, 255)); //设置第三条曲线的颜色为蓝色

}
定时器函数:
void CCodeAddCurve_1Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString str;
SYSTEMTIME st;
memset(&st, 0, sizeof(SYSTEMTIME));
GetLocalTime(&st);
str.Format("%02d:%02d",st.wMinute,st.wSecond);

m_TeeChart.Series(0).Add(75,str,1); // 此处900是人为设定的一个纵坐标输出值,lable是横坐标的输出值
m_TeeChart.Series(1).Add(60,str,1);
m_TeeChart.Series(2).Add(50,str,1);

m_TeeChart.GetAxis().GetBottom().Scroll(1.0,TRUE); // 将左侧的曲线移出界面
SetTimer(1,1000,NULL);

CDialog::OnTimer(nIDEvent);
}


但是若将以上程序做如下修改,teechart控件上就没有实时曲线显示了,哎…这是怎么回事额?不知道什么原因?


BOOL CCodeAddCurve_1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

m_TeeChart.Series(0).Clear();
m_TeeChart.Series(1).Clear();
m_TeeChart.Series(2).Clear();

InitChart();
SetTimer(1,1000,NULL);

return TRUE; // return TRUE unless you set the focus to a control
}
其中,InitChart();如下:
void CCodeAddCurve_1Dlg::InitChart()
{
CString str;
SYSTEMTIME st;
memset(&st, 0, sizeof(SYSTEMTIME));
GetLocalTime(&st);
str.Format("%02d:%02d",st.wMinute,st.wSecond);

//设置X轴与Y轴的标题:
m_TeeChart.GetAxis().GetLeft().GetTitle().SetCaption("temperature");
m_TeeChart.GetAxis().GetBottom().GetTitle().SetCaption("time");

m_TeeChart.Series(0).FillSampleValues(50); //向第一个Line序列中添加数据
m_TeeChart.Series(1).FillSampleValues(50); //向第二个Line序列中添加数据
m_TeeChart.Series(2).FillSampleValues(50); //向第二个Line序列中添加数据

m_TeeChart.Series(0).SetColor(RGB(255, 0, 0)); // 设置第一条曲线的颜色为红色
m_TeeChart.Series(1).SetColor(RGB(0, 255, 0)); //设置第二条曲线的颜色为绿色
m_TeeChart.Series(2).SetColor(RGB(0, 100, 255)); //设置第三条曲线的颜色为蓝色

m_TeeChart.Series(0).Add(75,str,1); // 此处900是人为设定的一个纵坐标输出值,lable是横坐标的输出值
m_TeeChart.Series(1).Add(60,str,1);
m_TeeChart.Series(2).Add(50,str,1);

}
定时器函数:
void CCodeAddCurve_1Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

m_TeeChart.GetAxis().GetBottom().Scroll(1.0,TRUE); // 将左侧的曲线移出界面
SetTimer(1,1000,NULL);

CDialog::OnTimer(nIDEvent);
}

麻烦各位帮小弟看看,为什么teechart界面上是空白的,没有曲线显示了,怎么会这样?????小弟感激不尽……
...全文
863 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ArthurKingYs 2015-05-29
  • 打赏
  • 举报
回复
为什么要弄两个timer函数 这样逻辑会很乱的

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧