TeeChart经验总结 11.Tools

不记得是从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 end

pas文件:

  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

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
=========================================== TeeChart Pro Activex Control v2018 MS .NET COMPATIBILITY Copyright (c) 1997-2018 by Steema Software SL All Rights Reserved. http://www.steema.com email: info@steema.com supportx@steema.com =========================================== Document updated: June 2004 TeeChart Pro Activex Control MS Visual Studio .NET compatibility notes =========================================== Please see the release.txt release notes for bugfix and feature information about this release. =========================================== Changes for NET compatibility - The Chart.Series(xx) read-only property has been replaced by a Function method (affects only code written in VC++ and similar languages that make direct reference to Get_ and Set_ of properties). The new Series method (called Series) changes visibly by removal of the property 'Get_' element of the Function. The change is required due to a current MS.NET import restriction causing non-import of ActiveX properties that have an index parameter (only affects the root level of controls !). For a VB application no code change is necessary. Please see the following notes for other environments. The original property has been hidden in the interface and renamed to aSeries keeping its existing Dispid to support backward compatibility with applications compiled with previous releases of TeeChart 5. - The TChart OnSeriesBeforeAdd method uses a boolean variable called 'Continue'. "continue" is a keyword in C# (the language used to interim compile TeeChart namespace information in .NET). This had caused an import problem with the earlier releases of Visual Studio .NET. As a precaution we have chosen to rename the parameter to 'MoreValues' for the TeeChart Pro ActiveX Control. Notes on use: ------------- - Constant names in NET require full reference by default: eg. AxTChart1.AddSeries(TeeChart.ESeriesClass.scLine) Upgrading existing projects: ---------------------------- Upgrading existing Visual Studio projects works without manual intervention in code for most simple projects. Notable points relating to import: VISUAL BASIC project: ===================== - Designtime saved content of a Chart does not always successfully import to a NET project. We recommend you open the project first in its current environment (eg. Visual Basic v6) and provoke a change in the Chart and resave the project. That will update the saved frx Chart information data to v5.0.3. Then save the Chart content as a tee file by right-clicking the Chart and selecting 'Export'. Some projects 'may' then import the saved Chart correctly without further steps required. If the Chart content doesn't import successfully then right-click on the Chart and import the saved tee file. If the project fails to import, clear the Chart content after saving it to tee (remove and replace the Chart with an empty one) and re-import following the above step to later import the saved tee file. - Calls to interfaces not supported. In Visual Studio v6 and prior versions, it was possible to connect components by interface. eg. TeeCommander.Chart=TChart1 This is no longer possible. You should use the integer link: eg. TeeCommander.ChartLink=TChart1.ChartLink - Colour definition requires update TeeChart colours map as UInt32 when imported to NET. The colour definition when applied takes the following form: .Labels.Font.Color = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Cyan)) - Some event syntax is incorrect on import. Notably the Mouse events which are 'duplicated' by default NET appointed events. If you find event syntax to be incorrect, modify the syntax as follows: eg. Private Sub TChart1_OnMouseUpEvent(ByVal eventSender As System.Object, _ ByVal eventArgs As AxTeeChart.ITChartEvents_OnMouseUpEvent) _ Handles TChart1.OnMouseUp 'do something End Sub - Some form object (eg. Checkbox) events may fire before the Chart is loaded. That didn't occur in VB6 and will require a workaround in VB.NET if Chart properties are referenced in this way at Form load. eg. taken from VB Drag Points example: 'Check1.CheckStateChanged may fire when form is intialized Private Sub Check1_CheckStateChanged(ByVal eventSender As System.Object, _ ByVal eventArgs As System.EventArgs) _ Handles Check1.CheckStateChan ' switch 2D / 3D view... TChart1.Aspect.View3D = Check1.CheckState ' enable scroll-bar only in 3D... HScroll1.Enabled = Check1.CheckState End Sub In the above event the View3D line will fail as the Chart isn't yet loaded when the event is called. An option to workaround it may be to set a boolean 'OK_To_Run' variable to set after the first Chart Repaint. eg. OK_To_Run false on load and set to true in Form_Load event after Chart is populated, etc. Private Sub Check1_CheckStateChanged(ByVal eventSender As System.Object, _ ByVal eventArgs As System.EventArgs) _ Handles Check1.CheckStateChan ' switch 2D / 3D view... If OK_To_Run = True Then TChart1.Aspect.View3D = Check1.CheckState End if ' enable scroll-bar only in 3D... HScroll1.Enabled = Check1.CheckState End Sub Microsoft recommend a similar step (add a IsInitializing property to the Form). We'll be taking a closer look at these issues to see if we can recommend less demanding steps to resolve them. VISUAL C++ project: ===================== The Series declaration has changed. The easiest way to upgrade the project is to import TeeChart classes before upgrading the project to .NET. 1. All references to 'GetSeries(xx)' should be changed to 'Series(xx)' That will call the new Series method that returns the Series Interface (just as the predecesor property did). The Series property has been name changed to aSeries, retaining its DispId to support existing compiled applications. 2. The following is handled automatically if you import the TeeChart classes. For reference, the following changes occur to the Series declaration. *Note you should not need to do anything if you import TeeChart to your project. a) In the TChart.h Class header file the GetSeries declaration changes to: CSeries Series(long SeriesIndex); b) In the TChart.cpp Class impl. file the GetSeries declaration changes to: CSeries CTChart::Series(long SeriesIndex) { LPDISPATCH pDispatch; static BYTE parms[] = VTS_I4; InvokeHelper(0x14, DISPATCH_METHOD, VT_DISPATCH, (void*)&pDispatch;, parms, SeriesIndex); return CSeries(pDispatch); } Projects should then compile without issue. =========================================== Use of Strong Named Assemblies =========================================== If you compile Strong Named Assemblies then imported ActiveX Controls must also be Strong Named. The Utilities folder contains a Strong Name compiled version of: \Utilities\VS.NET\Strong Named DLLs - AxInterop.TeeChart.dll - TeeChart.dll They may be used to replace the automatically generated AxInterop.TeeChart.dll and Interop.TeeChart.dll created when TeeChart AX is added to a Windows Form. You should remove auto-generated dlls from the references list in the project Solution Explorer and from the Obj folder of the project and Debug or Release Bin folder. Then copy in the new Dlls to Obj and Bin folders and reference the new Dlls from their Obj folder location. =========================================== Please send us details about any other issues found to: http://www.teechart.net/support/modules.php?name=Forums Many thanks ! =========================================== http://www.steema.com support: http://www.teechart.net/support/modules.php?name=Forums -------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值