不记得是从7.0还是8.0,TeeChart提供了丰富的Tools.这是一个纯用TeeChart的Tools实现的简易游标Demo.
本节后面会附上全部源码.Clip Series:当Series被拖动超出了Axis的范围,则超出的部分不显示.Cursor:十字,垂直,水平方向的游标,可以具体Snap任意Series的相应方向上的数据点.Drag Marks:可以任意拖动位置的Marks.Drag Point:可以任意移动绑定Series的数据点.Draw Line:在Chart上画线.Extra Legend:扩展Legend,可以在Chart再显示若干个Legend.fibonnaci:斐波那契数Gantt Drag:可拖动的甘特图Image:图片Legend Palette:用Series的颜色显示Legend颜色Mark Tips:鼠标移动到Mark上,会显示出Hint提示.Nearest Point:移动鼠标,会找到离鼠标最近的Series上的一点.Pie Slices:移动鼠标到Pie Slices上,会高亮被鼠标移动到的slice.Region:填充Series和某个值之间的区域.Series Animation:显示动画,比如柱状图从0增加到设定值.Series Band:填充2个Series之间的区域.Statistics:统计资料,可以显示一个Series的一些统计资料.比如平均值,最大值,最小值,多少个值等等.Surface Nearest:找到表面最近的点,并且高亮.
Axis Arrow:在Axis上添加2个方向的箭头,可以进行相应方向的Scroll操作.Axis Scroll:可以用鼠标直接拖动Axis进行数据范围的变更.Color Band:用彩色带填充Axis区域的背景颜色.Color Line:用彩色线(可以允许拖动)显示在相应Axis的区域.Grid Band:用2种颜色带交替填充相应Axis的区域.
2D Lighting:有点类似探照灯一样的效果...3D Grid Transpose:交换3D Series的数据,行,列.Annotation:注释,可以在Chart里任意位置显示一段文字.Anti-Alias:平滑线的尖角.Banner:横幅,可以实现滚动字.Data Table:显示一个Series的数据表格.Fader:淡入/淡出一个Chart.Frame:显示一个包围Chart的框架(相框效果).Full Screen:将Chart全屏显示,然后用Alt+F4或者Esc返回.Legend Scrollbar:Legend的滚动条Link:在Chart里显示一个超级链接.Magnify:一个可以来回拖动的放大镜.Page Number:显示Chart的当前页/总页数(也可以提供切换页的按钮).Rectangle:一个可以拖动,可以改变大小的文字显示框.Rotate:可以360度任意角度旋转Chart.Selector:可以设置选择任何在Chart中的子组件,比如Title,Series等等.组合Hint,可以显示出选中的是什么组件.SubChart:在Chart里再内置子Chart.Text 3D:显示3D的注释.Transpose Series:交换Series的行列.Video Creator:创建一段Chart图像的AVI.Video Player:在Chart里播放AVI.
下面是之前提到的Demo.dfm文件:
1 object Form1: TForm1 2 Left = 192 3 Top = 190 4 Width = 870 5 Height = 500 6 Caption = 'Form1' 7 Color = clBtnFace 8 Font.Charset = DEFAULT_CHARSET 9 Font.Color = clWindowText 10 Font.Height = -11 11 Font.Name = 'MS Sans Serif' 12 Font.Style = [] 13 OldCreateOrder = False 14 OnCreate = FormCreate 15 PixelsPerInch = 96 16 TextHeight = 13 17 object Button_FillData: TButton 18 Left = 744 19 Top = 48 20 Width = 75 21 Height = 25 22 Caption = '填充数据' 23 TabOrder = 0 24 OnClick = Button_FillDataClick 25 end 26 object CheckBox_Cursor: TCheckBox 27 Left = 752 28 Top = 88 29 Width = 57 30 Height = 17 31 Caption = '游标' 32 TabOrder = 1 33 OnClick = CheckBox_CursorClick 34 end 35 object CheckBox_LockY: TCheckBox 36 Left = 752 37 Top = 120 38 Width = 97 39 Height = 17 40 Caption = 'Lock Cursor Y' 41 TabOrder = 2 42 OnClick = CheckBox_LockYClick 43 end 44 object Chart1: TChart 45 Left = 24 46 Top = 32 47 Width = 681 48 Height = 409 49 Title.Text.Strings = ( 50 'TChart') 51 TabOrder = 3 52 end 53 endpas文件:
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 TeEngine, Series, StdCtrls, ExtCtrls, TeeProcs, Chart, TeeTools; 8 9 type 10 TForm1 = class(TForm) 11 Button_FillData: TButton; 12 CheckBox_Cursor: TCheckBox; 13 CheckBox_LockY: TCheckBox; 14 Chart1: TChart; 15 procedure Button_FillDataClick(Sender: TObject); 16 procedure FormCreate(Sender: TObject); 17 procedure CheckBox_CursorClick(Sender: TObject); 18 private 19 { Private declarations } 20 FFLS1, FFLS2: TFastLineSeries; 21 FCursorTool: TCursorTool; 22 FAnnotationTool: TAnnotationTool; 23 procedure CursorChange(Sender:TCursorTool; x,y:Integer; 24 Const XValue,YValue:Double; 25 Series:TChartSeries; 26 ValueIndex:Integer); 27 public 28 { Public declarations } 29 end; 30 31 var 32 Form1: TForm1; 33 34 implementation 35 36 {$R *.DFM} 37 38 procedure TForm1.Button_FillDataClick(Sender: TObject); 39 begin 40 FFLS1.FillSampleValues(20); 41 FFLS2.FillSampleValues(20); 42 end; 43 const 44 LabelInv = 10; 45 46 procedure TForm1.CursorChange(Sender: TCursorTool; x, y: Integer; 47 const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer); 48 var 49 Str: string; 50 TmpX, TmpY: Integer; 51 begin 52 FAnnotationTool.Visible := False; 53 if not Assigned(Series) then 54 Exit; 55 if Series.XValues.Count <= 0 then 56 Exit; 57 Str := Format('X Value = %.2f', [XValue]) + #13#10 58 + Format('%s YValue = %.2f',[FFLS1.Title, FFLS1.YValues[ValueIndex]]) + #13#10 59 + Format('%s YValue = %.2f',[FFLS2.Title, FFLS2.YValues[ValueIndex]]); 60 FAnnotationTool.Text := Str; 61 TmpX := x + LabelInv; 62 if TmpX + FAnnotationTool.Width > Chart1.ChartRect.Right - LabelInv then 63 TmpX := x - FAnnotationTool.Width - LabelInv; 64 if CheckBox_LockY.Checked then 65 begin 66 TmpY := Chart1.ChartRect.Top + LabelInv; 67 if TmpY + FAnnotationTool.Height > Chart1.ChartRect.Bottom - LabelInv then 68 TmpY := Chart1.ChartRect.Bottom - Height - LabelInv; 69 end 70 else 71 begin 72 TmpY := Chart1.GetCursorPos.y + LabelInv; 73 if TmpY + FAnnotationTool.Height > Chart1.ChartRect.Bottom - LabelInv then 74 TmpY := Chart1.ChartRect.Bottom - FAnnotationTool.Height - LabelInv; 75 end; 76 if TmpY < Chart1.ChartRect.Top + LabelInv then 77 TmpY := Chart1.ChartRect.Top + LabelInv; 78 FAnnotationTool.Top := TmpY; 79 FAnnotationTool.Left := TmpX; 80 FAnnotationTool.Visible := FCursorTool.Visible; 81 end; 82 83 procedure TForm1.FormCreate(Sender: TObject); 84 begin 85 //调整TeeChart属性 86 Chart1.Legend.Visible := True; 87 Chart1.Legend.Alignment := laTop; 88 Chart1.View3D := False; 89 Chart1.Zoom.Allow := False; 90 Chart1.AllowPanning := pmNone; 91 //创建Series 92 if not Assigned(FFLS1) then 93 begin 94 FFLS1 := TFastLineSeries.Create(Self); 95 FFLS1.ParentChart := Chart1; 96 FFLS1.Title := 'Test Series 1'; 97 end; 98 if not Assigned(FFLS2) then 99 begin 100 FFLS2 := TFastLineSeries.Create(Self); 101 FFLS2.ParentChart := Chart1; 102 FFLS2.Title := 'Test Series 2'; 103 end; 104 //创建Tools 105 FCursorTool := TCursorTool.Create(Chart1); 106 FCursorTool.ParentChart := Chart1; 107 FCursorTool.Active := False; 108 FCursorTool.Pen.Color := clRed; 109 FCursorTool.Style := cssVertical; 110 FCursorTool.Series := FFLS1; 111 FCursorTool.Snap := True; 112 FCursorTool.OnChange := CursorChange; 113 114 FAnnotationTool := TAnnotationTool.Create(Chart1); 115 FAnnotationTool.ParentChart := Chart1; 116 FAnnotationTool.Active := False; 117 FAnnotationTool.PositionUnits := muPixels; 118 FAnnotationTool.Shape.CustomPosition := True; 119 FAnnotationTool.Shape.Gradient.Visible := True; 120 FAnnotationTool.Shape.Transparency := 30; 121 end; 122 123 procedure TForm1.CheckBox_CursorClick(Sender: TObject); 124 begin 125 FCursorTool.Visible := CheckBox_Cursor.Checked; 126 FAnnotationTool.Visible := CheckBox_Cursor.Checked; 127 end; 128 129 end.转载于:https://www.cnblogs.com/solokey/archive/2011/07/27/2118693.html