TeeChart Pro提供了一個空的Chart Canvas做爲數據系列的背景。這意味着沒有預約義圖表類型。您能夠將所需的圖表類型定義爲要顯示的系列類型的混合。因爲某些系列類型的特殊性質,在圖表上混合使用一些系列類型是不切實際的。當您添加新系列時,TeeChart會經過在圖表庫中顯示不適合的系列類型來幫助您。您能夠在一個圖表中放置的系列數量沒有實際限制。函數
使用圖表編輯器(參見教程1)或按代碼添加系列。spa
procedure TForm1.Button2Click(Sender: TObject); var tmpLineSeries:TLineSeries; begin tmpLineSeries:=TLineSeries.Create(self); Chart1.AddSeries(tmpLineSeries); tmpLineSeries.FillSampleValues(10); end;
選擇系列的軸orm
添加到圖表中的系列將自動將左軸和下軸做爲參考軸。您能夠經過選擇相關係列的「系列常規」頁面來更改圖表編輯器中的參考軸。有4個軸可供選擇,Top,Left,Bottom和Right。經過代碼,更改軸將以下所示:教程
With Series1 do begin HorizAxis := aTopAxis; VertAxis := aRightAxis; end;
每一個軸能夠關聯1個以上的系列。TeeChart將決定適合與Axis匹配的系列的最佳比例,但您能夠本身更改Axis音階(參見Axis Tutorial)。能夠添加附加軸,它們將複製與前4個軸相對應的刻度(參見教程部分附加軸)。索引
鏈接系列事件
您可使用Series做爲另外一個Series的數據源。經過設置第二系列的數據源,可使用圖表編輯器完成此操做。轉到「系列」選項卡「數據源」頁面。選擇「Function」做爲數據源類型。將出現兩個列表框,可用系列和選定系列。選擇要用做當前系列的數據源的系列,而後在上面名爲Function:的Combobox中,選擇Copy做爲功能類型。請注意,以這種方式,任何Series均可以定義爲其餘Series的函數,Function Type能夠是Function組合框中可用的列表中的任何一個。要經過代碼執行相同操做,請參閱下文:get
procedure TForm1.BitBtn2Click(Sender: TObject); begin With Series2 do begin Datasource:=Series1; SetFunction(TAverageTeeFunction.Create(Self)); FunctionType.Period := 4; CheckDatasource; end end;
更改系列訂單 it
使用圖表編輯器能夠很是輕鬆地更改系列順序。轉到編輯器的首頁,突出顯示要移動的系列。使用右側的箭頭按鈕以系列順序向上或向下移動系列。系列訂單將決定系列在圖表中相對於其餘系列的相對顯示位置。經過代碼使用SeriesList屬性或ExchangeSeries方法。io
Chart1.ExchangeSeries(0, 1); //Change Series(0) with Series(1) in the index order
注意。交換Series後,系列的索引將被更改。所以,若是代碼從新運行,上面的代碼行將永久地交換2系列'0'和'1',由於0變爲1,1變爲0。
將系列設置爲「Active:=False」將從圖表中隱藏系列,但保持其數據內容不變。
TeeChart系列經過TChartValueList組件將其值存儲在可訪問和可修改的Valuelist中。
訪問系列值
您能夠訪問列表中的任何值:
ShowMessage(FloatToStr(Series1.XValues[3])); //Displays value of 4th point (index starts at 0) in Series1
以這種方式訪問的值可用於設置系列數據的陷阱條件:
With Series1 do begin For t := 0 To Count - 1 do begin If YValues[t] > 9 Then ShowMessage('Value: ' + FloatToStr(XValues[t]) + ', ' + FloatToStr(YValues[t]) + ' exceeds limit'); end; end;
能夠經過一些Series方法和幾個Chart事件使用的PointIndex點得到相同的值。
procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Showmessage('ValueIndex is: ' + IntToStr(ValueIndex)); Showmessage('Point''s Y value is: ' + FloatToStr(Sender.YValues.Value[ValueIndex])); Chart1.CancelMouse:=True; //Use CancelMouse to prevent Zoom event activating end;
單擊3D系列時,只有前平面上的單擊纔會被識別爲系列單擊。
使用值的示例
此代碼根據用戶的鼠標單擊修改BarSeries Bar的值。
//Use the OnClickSeries or OnClickBackground event to determine where the user has clicked.procedure TForm1.Chart1ClickBackground(Sender: TCustomChart; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin If (Int(Chart1.Axes.Bottom.CalcPosPoint(X)) > -1) Then Case Ord(Button) of 0 : UpdatePoint(Chart1.Axes.Bottom.CalcPosPoint(X), Chart1.Axes.Left.CalcPosPoint(Y)); end; end; procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin UpdatePoint(ValueIndex, Chart1.Axes.Left.CalcPosPoint(Y)); Chart1.CancelMouse:=True; //Use CancelMouse to prevent Zoom event activatingend;
在這兩種狀況下,請調用UpdatePoint Sub例程來修改Bar的值:
Procedure TForm1.UpdatePoint(Bar, Y : Double); begin If Round(Bar) < Series1.Count Then begin Series1.YValues[Round(Bar)] := Int(Y); Chart1.refresh; end; end;