MFC中用teechart控件做了一个实时动态曲线显示的程序,程序修改前
在以下程序中,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界面上是空白的,没有曲线显示了,怎么会这样?????小弟感激不尽……