轉(zhuǎn)帖|其它|編輯:郝浩|2012-10-23 10:26:44.000|閱讀 1109 次
概述:以前在網(wǎng)上看過很多TeeChart在VC環(huán)境下的使用心得,今天我也來總結(jié)一下TeeChart類的屬性和方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
以前在網(wǎng)上看過很多TeeChart在VC環(huán)境下的使用心得,今天我也來總結(jié)一下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中使用了眾多的屬性方法和事件,隨著版本的升級(jí)將越來越豐富。這使得TChart具有非常強(qiáng)大的功能。本文僅簡(jiǎn)單地介紹其中一些重要類的屬性和方法。
Series是要顯示的數(shù)據(jù)的主體。在一個(gè)圖表中可以有一個(gè)或多個(gè)序列,每個(gè)序列可以有不同的顯示類型,如Line、Bar、Pie等等。
Axes控制圖表坐標(biāo)軸的屬性,在缺省的情況下,坐標(biāo)軸可以自動(dòng)地根據(jù)不同的數(shù)據(jù)設(shè)置好標(biāo)度范圍和間隔,當(dāng)然也可以手工調(diào)整。
Legend控制圖表的圖例顯示。Legend是圖表中的一個(gè)長(zhǎng)方形的用來顯示圖例標(biāo)注的區(qū)域??梢詷?biāo)注Series的名稱或者Series中的項(xiàng)目和數(shù)值。
Panel可以設(shè)置圖表的背景??梢允褂脻u變的顏色或者圖像文件作為整個(gè)圖表的背景。
Canvas可以讓設(shè)計(jì)者繪制自己的圖形。使用方法和Delphi中的Canvas一樣。有TextOut、 LineTo、Arc等各種畫圖的方法可以調(diào)用。
TChart的一些屬性實(shí)際上是其他類的變量,這些類又具有自己的屬性和方法。如Ititles類又具有Text、Color、Font等屬性,我們可以用這些屬性來設(shè)置題頭的文本、顏色和字體。
TeeChart和其他的圖表控件相比,有一個(gè)非常重要的特點(diǎn)是TeeChart可以把圖表保存為一個(gè)JPEG格式的圖形文件。調(diào)用格式如下:
TChart.Export.SaveToJPEGFile (FileName,Gray,Performance,Quality,Width,Height)
其中FileName是JPEG文件的保存路徑和文件名,路徑應(yīng)該是操作系統(tǒng)中的絕對(duì)路徑,而不是IIS中的相對(duì)路徑,IIS對(duì)相應(yīng)的保存目錄應(yīng)該具有寫權(quán)限。Gray指明是否保存為黑白圖像。Performance指明JPEG是生成質(zhì)量?jī)?yōu)先還是速度優(yōu)先。Quality是一個(gè)0到100的整數(shù),100時(shí)JPEG質(zhì)量最好,但文件最大;Quality越小則生成的文件越小,但圖像質(zhì)量也隨之下降。
設(shè)定信息如下(該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); // 設(shè)置3條曲線的坐標(biāo)軸 ------------------------- 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); // 設(shè)置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)); // 設(shè)置3條曲線的名稱 m_Chart.Series(0).SetName("ZongFengGuan"); m_Chart.Series(1).SetName("LieCheGuan"); m_Chart.Series(2).SetName("ZhiDongGang"); //-----設(shè)定最大最小值 m_Chart.GetAxis().GetBottom().SetMinMax(minStar,minEnd); // minStar,minEnd要求自己去添加,這里用的是時(shí)間的范圍 //一般為起始時(shí)間和結(jié)束時(shí)間的范圍的 // 連接數(shù)據(jù)庫 ---------------------------------- CXDatabasedb; _RecordsetPtrpRs; CStringstrSql; if(!db.Connect("ACCESS","",GetRootDir()+"\\db1.mdb","","")) { AfxMessageBox("連接數(shù)據(jù)庫失敗!"); 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) { // 添加數(shù)據(jù)點(diǎn) ------------------------------ 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(); } // 斷開數(shù)據(jù)庫連接 ------------------------------ db.Disconnect(); }
后記:當(dāng)圖與表格同時(shí)顯示時(shí),加入一個(gè)TeeChartGrid控件并關(guān)聯(lián)一個(gè)變量,下面語句使Grid與Teechart關(guān)聯(lián)起來:
m_ctrlChartGrid.SetChartLink(m_ctrlChart.GetChartLink());
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:新浪博客