原創(chuàng)|其它|編輯:郝浩|2012-10-19 17:10:15.000|閱讀 2704 次
概述:TeeChart圖表控件在VC++ 平臺(tái)上的運(yùn)用實(shí)例第三部分
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
在前面兩篇的文章中已經(jīng)對(duì)TeeChart圖表控件在VC++ 平臺(tái)上的運(yùn)用實(shí)例進(jìn)行了部分的講解,請(qǐng)參見(jiàn)《TeeChart圖表控件在VC++平臺(tái)上的運(yùn)用(一)》,《TeeChart圖表控件在VC++平臺(tái)上的運(yùn)用(二)》
下面接著上面的部分進(jìn)行:
選擇Tools表單,添加TeeChart工具,并作相關(guān)設(shè)置:
設(shè)置完畢后,對(duì)話(huà)框變?yōu)椋?/p>
在CMyTeeChartDlg類(lèi)的OnInitDialog()函數(shù)里添加下面的代碼:
// TODO: Add extra initialization here m_ctrlChart.Series(0).Clear(); m_ctrlChart.GetPage().SetMaxPointsPerPage(60); srand((int)time(0)); char strTime[25]; for(int i=0; i<60; i++) { itoa(i,strTime,10); int dTemper = rand()%100; m_ctrlChart.Series(0).AddXY(i,dTemper,strTime,RGB(255,0,0)); } m_ctrlChart.GetAxis().GetLeft().SetMinMax(0, 100);
這段代碼生成60個(gè)0~100之間的隨機(jī)數(shù),作為曲線(xiàn)顯示數(shù)據(jù)。
利用Class Wizard添加TeeChart控件對(duì)象的OnMouseMove消息處理函數(shù):
void CMyTeeChartDlg::OnMouseMoveTchart1(long Shift, long X, long Y) { // TODO: Add your control notification handler code here int mPoint = -1; double xValue = m_ctrlChart.Series(0).XScreenToValue(X) + 0.5; mPoint = (int)(xValue); if(mPoint < 0) { return ; } CValueList xList = m_ctrlChart.Series(0).GetXValues(); CValueList yList = m_ctrlChart.Series(0).GetYValues(); CString strXLabel = m_ctrlChart.Series(0).GetPointLabel(mPoint); int dYLabel = (int)yList.GetValue(mPoint); CToolList tlist = m_ctrlChart.GetTools(); CTools tools = tlist.GetItems(1); CAnnotationTool anntool = tools.GetAsAnnotation(); CString strTopNote; strTopNote.Format("Time: %ss Temperature: %3d ℃",strXLabel, dYLabel); anntool.SetText(strTopNote); }
編譯前要加入下列頭文件:
#include "Series.h"
#include "Axis.h"
#include "page.h"
#include "ValueList.h"
#include "ToolList.h"
#include "Tools.h"
#include "AnnotationTool.h"
#include "Axes.h"
#include <ctime>
編譯無(wú)誤后即可運(yùn)行。運(yùn)行結(jié)果如下圖,鼠標(biāo)在曲線(xiàn)上移動(dòng)時(shí),會(huì)顯示相關(guān)點(diǎn)的坐標(biāo)。
至此簡(jiǎn)單介紹了利用TeeChart控件在VC++編程平臺(tái)上繪制曲線(xiàn)的過(guò)程。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:新浪博客