在圖表上混合系列類型
TeeChart Pro提供了一個空的Chart Canvas作爲數據系列的背景。這意味着沒有預定義圖表類型。您可以將所需的圖表類型定義爲要顯示的系列類型的混合。由於某些系列類型的特殊性質,在圖表上混合使用一些系列類型是不切實際的。當您添加新系列時,TeeChart會通過在圖表庫中顯示不適合的系列類型來幫助您。您可以在一個圖表中放置的系列數量沒有實際限制。
添加新系列
使用圖表編輯器(參見教程1)或按代碼添加系列。
procedure TForm1.Button2Click(Sender: TObject); var tmpLineSeries:TLineSeries; begin tmpLineSeries:=TLineSeries.Create(self); Chart1.AddSeries(tmpLineSeries); tmpLineSeries.FillSampleValues(10); end;
選擇系列的軸
添加到圖表中的系列將自動將左軸和下軸作爲參考軸。您可以通過選擇相關係列的“系列常規”頁面來更改圖表編輯器中的參考軸。有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組合框中可用的列表中的任何一個。要通過代碼執行相同操作,請參閱下文:
procedure TForm1.BitBtn2Click(Sender: TObject); begin With Series2 do begin Datasource:=Series1; SetFunction(TAverageTeeFunction.Create(Self)); FunctionType.Period := 4; CheckDatasource; end end;
更改系列訂單
使用圖表編輯器可以非常輕鬆地更改系列順序。轉到編輯器的首頁,突出顯示要移動的系列。使用右側的箭頭按鈕以系列順序向上或向下移動系列。系列訂單將決定系列在圖表中相對於其他系列的相對顯示位置。通過代碼使用SeriesList屬性或ExchangeSeries方法。
Chart1.ExchangeSeries(0, 1); //Change Series(0) with Series(1) in the index order
注意。交換Series後,系列的索引將被更改。因此,如果代碼重新運行,上面的代碼行將永久地交換2系列'0'和'1',因爲0變爲1,1變爲0。
將系列設置爲“Active:=False”將從圖表中隱藏系列,但保持其數據內容不變。
系列value表
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;
購買TeeChart Pro VCL/FMX正版授權,請點擊“諮詢在線客服”喲!