TeeChart绘图:
通过CTchart 的get_SeriesCount函数获得所有图像序列,再全部清除
1. for(long i = 0;i<m_TeeChart.getSeriesCount();i++)
2. {
3. ((CSeries)m_TeeChart.Series(i)).Clear();
4. }
AddXY就是一个一个加入点,在点数不多,且需要动态显示的时候是不错的选择。点数多的情况下嘛,那就还是用AddArray了
先看看AddXY
[cpp] view plaincopy
1. const UINT nDATALENGTH=100;
2. double dData[nDATALENGTH];
3. for (int i=0;i<nDATALENGTH;i++)
4. {
5. dData[i] = 100 * sin((float)i)*cos((float)4*i);
6. }
7. //ClearAllSeries();
8. CSeries lineSeries = (CSeries)m_TeeChart.Series(0);
9. lineSeries.Clear();//在最前面加上ClearAllSeries(ClearAllSeries是自己写的函数)就不用了
10. for(int i=0;i<nDATALENGTH;i++)
11. {
12. lineSeries.AddXY((double)i,dData[i],NULL,0);
13. }
AddXY的第一个参数是x点坐标,第二个是y点坐标,第三个参数是为了使x坐标特殊显示,这是会替换掉x坐标的显示内容,如我想显示“点xx“可以这样
[cpp] view plaincopy
1. CString str;
2. for(int i=0;i<nDATALENGTH;i++)
3. {
4. str.Format(_T("点%d"),i);
5. lineSeries.AddXY((double)i,dData[i],str,0);
6. }
str.Format(_T("单位(ns)"));
m_tabch1.m_tChart_CH1.GetAxis().GetBottom().GetTitle().SetCaption(str);
m_tabch1.m_tChart_CH1.GetAxis().GetLeft().GetTitle().SetCaption(str);
//设置纵坐标最大值
m_tabch1.m_tChart_CH1.GetAxis().GetLeft().SetMinMax(-5,5);
//不隐藏图例
m_tabdoublech.m_tChart_DouCH1.GetLegend().SetVisible(TRUE);
绘制坐标显示:
void TabCh1::OnMouseMoveTchart1(long Shift,long X, long Y)
{
//TODO: 在此处添加消息处理程序代码
longx1,y1,x2,y2;
doubleposX,posY;
CStringstr;
m_tChart_CH1.Repaint();
x1= m_tChart_CH1.GetAxis().GetLeft().GetPosition();
y1= m_tChart_CH1.GetAxis().GetTop().GetPosition();
x2= m_tChart_CH1.GetAxis().GetRight().GetPosition();
y2= m_tChart_CH1.GetAxis().GetBottom().GetPosition();
if(X>=x1&&Y>=y1&&X<=x2&&Y<=y2)
{
m_tChart_CH1.GetCanvas().DrawLine(x1,Y,x2,Y);
m_tChart_CH1.GetCanvas().DrawLine(X,y1,X,y2);
}
posX =m_tChart_CH1.GetAxis().GetBottom().CalcPosPoint(X);
posY = m_tChart_CH1.GetAxis().GetLeft().CalcPosPoint(Y);
//posX0 = posX;
//posY0 = posY;
POSXY_Ch1.posX0 = posX;
POSXY_Ch1.posY0 = posY;
str.Format(_T("X:%fY:%f\r\n"),posX, posY);
GetDlgItem(IDC_STATIC1)->SetWindowText(str);
}
void DrawLine(double* pX, double* pY, longnNum, CSeries lineSeriesCH)
{
COleSafeArrayXValues;
COleSafeArrayYValues;
longi = 0;
DWORDwLength = nNum;
XValues.Create(VT_R8,1, &wLength);
YValues.Create(VT_R8,1, &wLength);
for(i=0;i<nNum; i++)
{
XValues.PutElement(&i,pX);
YValues.PutElement(&i, pY);
}
lineSeriesCH.Clear();
lineSeriesCH.AddArray(nNum,YValues,XValues);
// lineSeriesCH.put_Color(RGB(255,100,255)); //颜色设置
}