在使用CXGraph作图的时候,有时候会遇到需要给一条曲线添加标注或者需要在整个图上添加一些标注。
第一步,初始化CXGraph
m_Graph.Create(_T("XGraph"),_T(""), WS_CHILD | WS_VISIBLE, clRect, this, 23119 );
第二步,给CXGraph添加数据
m_Graph.SetData (m_Values[0], VALCOUNT, 0, 0, 0);
第三步,给图片上添加标注
CRect clRectLable(50,10,200,30);//先创建一个矩形,并规定矩形所在的位置
CXGraphLabel& m = m_Graph.InsertLabel(clRectLable,"ssss");//给图片添加一个label并初始化label中的注释
m_label = &m;
m_label->SetTransparent(true);//设置透明
m_label->SetBorder(false);//设置边框
第四步,修改label中的注释
CString str;
str.Format("%.2fnm,%.2fum",fYMax-fYMin,fXMax-fXMin);
m_label->SetText(str);
其他,如果需要对一条曲线做注释的话,可以用m_Graph.GetCurve (0).SetLabel("Curve 1")方法。