原創|其它|編輯:郝浩|2012-10-19 17:10:15.000|閱讀 2704 次
概述:TeeChart圖表控件在VC++ 平臺上的運用實例第三部分
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在前面兩篇的文章中已經對TeeChart圖表控件在VC++ 平臺上的運用實例進行了部分的講解,請參見《TeeChart圖表控件在VC++平臺上的運用(一)》,《TeeChart圖表控件在VC++平臺上的運用(二)》
下面接著上面的部分進行:
選擇Tools表單,添加TeeChart工具,并作相關設置:
設置完畢后,對話框變為:
在CMyTeeChartDlg類的OnInitDialog()函數里添加下面的代碼:
// 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個0~100之間的隨機數,作為曲線顯示數據。
利用Class Wizard添加TeeChart控件對象的OnMouseMove消息處理函數:
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>
編譯無誤后即可運行。運行結果如下圖,鼠標在曲線上移動時,會顯示相關點的坐標。
至此簡單介紹了利用TeeChart控件在VC++編程平臺上繪制曲線的過程。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:新浪博客