轉帖|其它|編輯:郝浩|2012-10-23 10:26:44.000|閱讀 1109 次
概述:以前在網上看過很多TeeChart在VC環境下的使用心得,今天我也來總結一下TeeChart類的屬性和方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
以前在網上看過很多TeeChart在VC環境下的使用心得,今天我也來總結一下TeeChart類的屬性和方法。
>>>TeeChart下載
首先在頭文件中要加上:
#include "tchart.h" #include "series.h" #include "valuelist.h" #include "axes.h" #include "axis.h" #include "pen.h" #include "axislabels.h" #include "teefont.h" #include "axistitle.h" #include "aspect.h" #include "fastlineseries.h" #include "titles.h" #include "fastlineseries.h" #include "panel.h" #include "legend.h" #include "tools.h" #include "toollist.h" #include "annotationtool.h" #include "page.h"
TeeChart類的屬性和方法
TeeChart的主類是TChart。TChart中使用了眾多的屬性方法和事件,隨著版本的升級將越來越豐富。這使得TChart具有非常強大的功能。本文僅簡單地介紹其中一些重要類的屬性和方法。
Series是要顯示的數據的主體。在一個圖表中可以有一個或多個序列,每個序列可以有不同的顯示類型,如Line、Bar、Pie等等。
Axes控制圖表坐標軸的屬性,在缺省的情況下,坐標軸可以自動地根據不同的數據設置好標度范圍和間隔,當然也可以手工調整。
Legend控制圖表的圖例顯示。Legend是圖表中的一個長方形的用來顯示圖例標注的區域。可以標注Series的名稱或者Series中的項目和數值。
Panel可以設置圖表的背景。可以使用漸變的顏色或者圖像文件作為整個圖表的背景。
Canvas可以讓設計者繪制自己的圖形。使用方法和Delphi中的Canvas一樣。有TextOut、 LineTo、Arc等各種畫圖的方法可以調用。
TChart的一些屬性實際上是其他類的變量,這些類又具有自己的屬性和方法。如Ititles類又具有Text、Color、Font等屬性,我們可以用這些屬性來設置題頭的文本、顏色和字體。
TeeChart和其他的圖表控件相比,有一個非常重要的特點是TeeChart可以把圖表保存為一個JPEG格式的圖形文件。調用格式如下:
TChart.Export.SaveToJPEGFile (FileName,Gray,Performance,Quality,Width,Height)
其中FileName是JPEG文件的保存路徑和文件名,路徑應該是操作系統中的絕對路徑,而不是IIS中的相對路徑,IIS對相應的保存目錄應該具有寫權限。Gray指明是否保存為黑白圖像。Performance指明JPEG是生成質量優先還是速度優先。Quality是一個0到100的整數,100時JPEG質量最好,但文件最大;Quality越小則生成的文件越小,但圖像質量也隨之下降。
設定信息如下(該CHART控件名稱為:m_Chart)
//清空chart ----------------------------------- m_Chart.ClearChart(); m_Chart.RemoveAllSeries(); //CHART框架 m_Chart.GetFrame().SetVisible(true); m_Chart.GetFrame().SetColor(RGB(255,255,255)); m_Chart.GetPanel().SetColor(RGB(255,255,255)); m_Chart.GetLegend().SetVisible(false); // 添加3條曲線 --------------------------------- m_Chart.AddSeries(0); m_Chart.AddSeries(0); m_Chart.AddSeries(0); // 設置3條曲線的坐標軸 ------------------------- m_Chart.Series(0).SetVerticalAxis(0); m_Chart.Series(1).SetVerticalAxis(0); m_Chart.Series(2).SetVerticalAxis(0); m_Chart.Series(0).SetHorizontalAxis(1); m_Chart.Series(1).SetHorizontalAxis(1); m_Chart.Series(2).SetHorizontalAxis(1); m_Chart.Series(0).GetXValues().SetDateTime(true); m_Chart.Series(1).GetXValues().SetDateTime(true); m_Chart.Series(2).GetXValues().SetDateTime(true); // 設置3條曲線的顏色 --------------------------- m_Chart.Series(0).SetColor(RGB(255,0,0)); m_Chart.Series(1).SetColor(RGB(0,255,0)); m_Chart.Series(2).SetColor(RGB(0,0,255)); // 設置3條曲線的名稱 m_Chart.Series(0).SetName("ZongFengGuan"); m_Chart.Series(1).SetName("LieCheGuan"); m_Chart.Series(2).SetName("ZhiDongGang"); //-----設定最大最小值 m_Chart.GetAxis().GetBottom().SetMinMax(minStar,minEnd); // minStar,minEnd要求自己去添加,這里用的是時間的范圍 //一般為起始時間和結束時間的范圍的 // 連接數據庫 ---------------------------------- CXDatabasedb; _RecordsetPtrpRs; CStringstrSql; if(!db.Connect("ACCESS","",GetRootDir()+"\\db1.mdb","","")) { AfxMessageBox("連接數據庫失敗!"); return; } strSql.Format("select * from %s where RunTime>=#%s# and RunTime<=#%s#",m_strTableName,strMinTime,strMaxTime); pRs = db.ExecuteSql(strSql); while(pRs!=NULL && !pRs->adoEOF) { // 添加數據點 ------------------------------ double dTime = oletime2chttime(COleDateTime(pRs->GetCollect("RunTime"))); double dZFGPress = var2dbl(pRs->GetCollect("ZFGPress")); double dLCGPress = var2dbl(pRs->GetCollect("LCGPress")); double dZDGPress = var2dbl(pRs->GetCollect("ZDGPress")); m_Chart.Series(0).AddXY(dTime,dZFGPress,NULL,RGB(255,0,0)); m_Chart.Series(1).AddXY(dTime,dLCGPress,NULL,RGB(0,255,0)); m_Chart.Series(2).AddXY(dTime,dZDGPress,NULL,RGB(0,0,255)); pRs->MoveNext(); } // 斷開數據庫連接 ------------------------------ db.Disconnect(); }
后記:當圖與表格同時顯示時,加入一個TeeChartGrid控件并關聯一個變量,下面語句使Grid與Teechart關聯起來:
m_ctrlChartGrid.SetChartLink(m_ctrlChart.GetChartLink());
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:新浪博客