您的位置:首页 > 理论基础 > 计算机网络

TChart用法(网络收集二)

2010-05-10 15:10 519 查看

TChart用法(网络收集二)

Posted on 2009-03-29 09:40 - - . -(yi,jian,dao) 阅读(2525) 评论(0) 编辑 收藏 所属分类: 未整理


TChart使用经验小结

1、问题:通过Addxy方法给TChart添加标记(Mark)时,发现在TChart的横坐标会随着Mark而变化,后来发现通过以下方法可避免这种情况:双击TChart,点击Axis-> top or bottom ->labels,在styles中将labels的形式改为Value即可!
2、几个有用的属性:
图表上的每个点都是有索引的,就象一个数组一样,在OnClickSeries事件中有个ValueIndex属性,该属性可以得到鼠标所点击的点的索引值(必须将Series的Point设置为可见,鼠标点击到那个点时才可以触发该事件)。
xValue[index]、yValue[index]分别表示图表的索引为index的横纵坐标值,用这两个属性可以读取和设置索引为index的点的值,注意:不要用xValues和yValues,这两个属性也可以达到同样的目的,但是速度非常的慢。因为后两个在进行操作的时候可能要遍历整个图表上的值(个人观点)
在MouseDown,MouseMove,Mouseup中,可以利用xScreentoValue(x),yScreentoValue(y)得到鼠标当时所在点对应在图表上的横纵坐标值。
e.g......
private
Nowindex:Integer;
Cantuo:boolean;
........
procedure TfrmMain.Chart1ClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
NowIndex:=ValueIndex;
end;
procedure TfrmMain.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Cantuo:=true;
end;
procedure TfrmMain.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Cantuo:=false;
end;
procedure TfrmMain.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Cantuo then
begin
Series1.yValue[NowIndex]:= Series1.yScreenToValue(y) ;
end;
end;
这里即实现了可以在图表中拖动某一个点使其在纵轴上变化位置
Tchart分析报告
1 Tchart分析报告
1.1 [概述]
TChart是delphi里面一个标准的图形显示控件。它可以静态设计(at design time)也可以动态生成。
1.2 [继承关系]

TObject
TPersistent
TComponent
TControl
TCustomControl
TWedgetControl
TChart
TCustomPanel
1.3 [tips]
1.3.1 Pro Version支持Bezier , Contour , Radar point3D 曲线
1.3.2支持jpeg文件的导出
1.3.3 Chart中的Series 可以连接到Table , Query , RemoteDataset(其他数据集)
1.3.4 TChart里的seriesactive属性可以实现对已绘制图形的显示或者隐藏
1.3.5TChart, tchartSeries是所有具体series的父类,没有画出什么来的,用一个具体的series类来创建就可以了,比如用TLineSeriesTPieSeries TPointSeries TPointSeries等等都行
1.3.6 TTeeFunction Component可以实现在同一个TChart里面,一个Serries对另一个Serries的统计

1.4 [问题极其使用技巧]
1.4.1 TChart中如何实现只有Y轴的放大与缩小功能?
设置BottomAxis或者LeftAxis的Automatic:=false并同时设置Minimum,Maximum属性
1.4.2如何固定TChart中的坐标,不使TChart中的坐标跟随Series的变化而变化?
//设置底座标
with myChart.BottomAxis do
begin
Automatic:=false;
Minimum:=0;
LabelStyle := talText;
end;
//设置左坐标
with myChart.LeftAxis do
begin
Automatic:=false;
Minimum:=0;
Title.Angle:=270;
Title.Font:=Self.Font;
Title.Font.Charset:=ANSI_CHARSET;
Title.Font.Name:='@宋体';
Grid.Visible := False;
end;
//设置右坐标
with myChart.RightAxis do
begin
Automatic:=false;
Title.Font:=Self.Font;
Title.Font.Charset:=ANSI_CHARSET;
Title.Font.Name:='@宋体';
Title.Caption:='累计百分比(%)';
Maximum:=100;
Minimum:=0;
end;
1.4.3如何删除一个图形中的一个点?
使用Series的delete 方法
1.4.4如何修改一个点的X或者Y 值?
LineSeries1.YValue[3] := 27.1 ;
{In Bubble Series}
BubbleSeries1.RadiusValues.Value[ 8 ] := 8.1 ;
{In Pie Series}
PieSeries1.PieValues.Value[ 3 ] := 111 ;
1.4.5如果横坐标是时间(日期),如何进行设置?
{First, you need to set the DateTime property to True in the desired X and/or Y values list.}
LineSeries1.XValues.DateTime := True ;
{Second, use the same above described methods, but give the values as Date, Time or DateTime values}
LineSeries1.AddXY( EncodeDate( 1996 , 1 , 23 ) , 25.4 , 'Barcelona' , clGreen );
1.4.6如何在chart中画出的曲线某个点上标记出该点的值?
Series.Marks.Visible:=true;
Series.Marks.Style:=smsValue;
1.4.7如何设置横轴或者纵轴的增长率?
Chart.BottomAxis.Increment := DataTimeStep[ dtOneHour ] ;
Chart.RightAxis.Increment := 1000;
1.4.8如何对图象进行缩放?
TChart的ZoomRect或者ZoomPercent方法 (Pie图可能不支持缩放)
1.5 [TChart可以绘制的图形]
1.5.1 Line ( TLineSeries)
1.5.2 FastLine (TFastLineSeries) 相对Line来说,它损耗了某些属性从而来实现快速绘制
1.5.3 Bar (TBarSeries)
1.5.4 Horizontal bar (THorizBarSeries)
1.5.5 Area (TAreaSeries)
1.5.6 Point (TPointSeries)
1.5.7 Pie (TPieSeries)
1.5.8 Arrow (TArrowSeries)
1.5.9 Bubble (TBubbleSeries)
1.5.10 Gantt (TGanttSeries)
1.5.11 Sharp (TChartShape)
1.6 [TChart的实时绘制]
实时绘制对机器性能要求比较高,因此我们在编程的时候要注意下面几个方面:
ü 使用2D图形
ü 是Chart尽可能包含少的点
ü 如果需要,可以移除(remove)chart的legend(?????)和Title
ü 使用默认的字体和字体大小
ü 使用FastLineSeries
ü 使用实体(solid)画笔和画刷格式
ü 尽量避免使用圆形和环行bar样式
ü 不要使用背景图片和渐变效果样式
ü 把Chart的BevelInner和BevelOUter属性设置为bcNone
ü 如果需要,把TChart的AxisVisible属性设置为False
ü 把BufferedDisplay设置为false可以加速chart的重绘
1.7 [Scrolling]
TChart有4中scroll选择(AllowPanning属性),分别是 不允许Scroll ( pmNone) ; 水平Scroll (pmHorizontal) ; 垂直Scroll (pmVertical) ; 水平和垂直Scroll (pmBoth)
Procedure Scroll(Const Offset:Double; CheckLimits:Boolean);
例子如下:
Chart1.BottomAxis.Scroll( 1000, True );这段代码也等同于
With Chart1.BottomAxis do
Begin
Automatic:=false;
SetMinMax( Minimum+1000, Maximum+1000 );
End;
1.8 [TChart中的全局变量]
1.9 ü TeeScrollMouseButton := mbRight;设置鼠标右键为TChart滚动键(默认)
ü TeeScrollKeyShift := [ ssCtrl ]; 要按住Control键才可以使Scroll滚动

1.9 [TChartSerries使用技巧]
1.9.1运行时候创建一个Serries, 三种方法:
1.Var MySeries : TBarSeries ;
MySeries := TBarSeries.Create( Self );
MySeries.ParentChart := Chart1 ;
2.Chart1.AddSeries( TBarSeries.Create( Self ) );
3.Var MyClass : TChartSeriesClass;
MyClass := TBarSeries ;
Chart1.AddSeries( MyClass.Create( Self ) );
1.9.2获得TChart中的Serries数组,也有三种方法
1.MySeries := Chart1.SeriesList [ 0 ]
2.MySeries := Chart1.Series [ 0 ]
3.MySeries := Chart1 [ 0 ]
1.9.3 SerriesCount属性获得SeriesListSeries的个数
1.9.4隐藏TChart中的Series有三种方法,但是效果不等价
1. Series1.Active:=False; 仅仅隐藏,当设置为true的时候还可以显示出来
2. Series1.ParentChart:=nil ; 隐藏,重新设置ParentChart为TChart时候可以显示
3. Series1.Free; 删除了Series. 不可以恢复
1.9.5 TChart中的数据排序
With Series1 do
begin
YValues.Order:=loAscending;
YValues.Sort;
Repaint;
end;
Ø 定位一个点(Loacate a point)
Series1.XValues.Locate(123);
Ø XValue和YValue都拥有的属性Total , TotalABS , MaxValue , MinValue

teechart笔记(Delphi)
来自:bobo 日期:2006-12-4 23:09:07 全文阅读:loading... 分类:学习札记
1.series的方法
1.1 ColorRange设定一定范围的点和线的颜色。
procedure ColorRange(AValueList: TChartValueList; Const FromValue, ToValue: Double; AColor: TColor);
其中:The TChartValueList component is the container of point values.
Each Series component has one or more values lists.
The XValues and YValues properties are TChartValueList components.
可以是XValues 或YValues;FromValue, ToValue是范围。AColor是点的颜色。
UnitTeEngine
DescriptionThis method will change the Color of a specified range of points.
The FromValue and ToValue parameters are the beginning and end of the specified AValueList range.

AValueList can be any Series ValueList such as: XValues, YValues, etc.
对某一特定的点:可以用series.valuecolor[index]属性
property ValueColor[Index: Integer]: TColor;
Use the ValueColor property to get or set the Color of a point at a particular position. Index gives the position of the point, where 0 is the first, 1 is the second, and so on.
不过这两个方法都会导致线的颜色也会改变:改变的模式是若下一点出界,则从此点到下一点的连线的颜色变为指定点的颜色。
用这种方法可以改变各个点的形状,result即是具体点的形状。
function TForm1.Series1GetPointerStyle(Sender: TChartSeries;
ValueIndex: Integer): TSeriesPointerStyle;
begin
if ValueIndex mod 2=0 then result:=psRectangle
else result:=psTriangle;
end;
1.2 CalcXPosValue 把某一轴X/Y轴的值,转化为窗体的像素值(整型)。
CalcXPosValue(Const Value: Double): Integer;
UnitTeEngine
DescriptionReturns the pixel Screen Horizontal coordinate of the specified Value.
for example:
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var tmp : Integer;
begin
tmp:=Series1.CalcPosValue( 123 );
with Chart1.Canvas do
Rectangle(tmp-5,tmp-5,tmp 5,tmp 5);
end;
1.3 画水平直线Chart1AfterDraw的时间中
Procedure TForm1.DBChart1AfterDraw(Sender: TObject);
begin
drawLimits(ChrtNum, width: integer; Value: Double; color: TColor);
end;
drawLimits(ChrtNum, width: integer; Value: Double; color: TColor);
var
PixValue:integer;
begin
with dbcht1.Canvas do
begin
PixValue := seriesx.CalcYPosValue(Value);
if (PixValue<dbcht1.ChartRect.Top) or (PixValue>dbcht1.ChartRect.Bottom) then//判断是否已经超出dbcht1.ChartRect的范围。
Pen.Color:=dbcht1.Color
else
Pen.Color := color;
Pen.Width := width;
MoveTo(dbcht1.ChartRect.Left, PixValue);
LineTo(dbcht1.ChartRect.Right, PixValue);
end;
end;
1.4 通过函数function来画直线/各种自定义曲线;
series|dataSource|function. 在object treeView对象观察器中 series1|TeeFunction1 的OnCalculate事件中添加公式
procedure TForm1.TeeFunction1Calculate(Sender: TCustomTeeFunction;
const x: Double; var y: Double);
begin
y:=50;
//y:=Sin(x/10);
end;
1.5 取消chart的网格
在chart|axis|Ticks|grid…中操作,此操作针对某一轴而言,如leftaxis,对于bottomaxis要选择它再操作。
1.6 mark tips显示数据标签的chart工具。
设定自定义的标签的方法:
设定一个单元局部变量 MarkText:string
在chart的onMouseMove中添加事件。
procedure TfrmVChart.dbcht1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var tmp: Integer;
begin
tmp := SeriesX.Clicked(x, y);//返回该点的所在的series上序号,从0开始。
if tmp = -1 then //没有点中曲线上的点。
labelText := ''
else
begin
MarkText := '序号:' FloatToStr(SeriesX.XValue[tmp]) #13 '数值:';
MarkText := labelText FormatFloat('#,##0.####',SeriesX.YValue[tmp]) #13 'XUCL:' FormatFloat('#,##0.####',XUCL);
MarkText := labelText #13 'XCL :' FormatFloat('#,##0.####',XCL) #13 'XLCL:' FormatFloat('#,##0.####',XLCL);
end;
end;
再在marktipstools的GetText事件中添加代码,修改要显示的值。
procedure TfrmVChart.ChartTool1GetText(Sender: TMarksTipTool;
var Text: string);
begin
Text := MarkText;
end;
1.7 自定义轴的标签(Label)
procedure TAxisItemsDemo.FormCreate(Sender: TObject);
begin
inherited;
Series1.AddArray([200,0,123,300,260,-100,650,400]);//添加数据
AddCustomLabels;
end;
Procedure TAxisItemsDemo.AddCustomLabels;
begin
with Chart1.Axes.Left do
begin
Items.Clear; // remove all custom labels//删除原有的标签。
// add custom labels
Items.Add(123,'Hello').Font.Size:=16;
Items.Add(466,'Good'#13'Bye').Transparent:=False;
Items.Add(300);
with Items.Add(-100) do //标签的一些属性。
begin
Transparent:=False;
Transparency:=50;
Color:=clBlue;
end;
end;
end;
1.8 teefunction,自定义函数的功能。
属性:munPoints:计算次数
Period:两次计算之间的x值的增量
starX:X的开始值。
periodStyle:period的方式,当是datetime类型时,很有用。如:Period:DateTimeStep[ dtOneMonth ],或DateTimeStep[ dtOneDay ]

1.9 teefunction的periodStyle
So, for example you can now plot the, for example, monthly average of sales function just using a normal Average function on a date-time source series and setting the function period to one month :
{ Place a Series1 and fill it with datetime data values at runtime (or from a database) }
Series2.SetFunction( TAverageTeeFunction.Create ) ;
Series2.FunctionType.PeriodStyle:=psRange;
Series2.FunctionType.Period:=DateTimeStep[ dtOneMonth ];
Series2.DataSource:=Series1 ;
This will result in several points, each one showing the average of each month of data in Series1.
It's mandatory that points in the source Series1 should be sorted by date when calculating functions on datetime periods.
The range can also be used for non-datetime series:
Series2.SetFunction( TAverageTeeFunction.Create ) ;
Series2.FunctionType.PeriodStyle:=psRange;
Series2.FunctionType.Period:=100;
Series2.DataSource:=Series1 ;
This will calculate an average for each group of points inside every 100 interval.
(Points with X >=0, X<100 will be used to calculate the first average, points with X >=100, X<200 will be used to calculate the second average and so on... )
Notice this is different than calculating an average for every 100 points.
在表单上增加一个Chart1,在FormCreate事件中添加
Chart1->AddSeries(new TPieSeries(Chart1)); //  添加一个饼形图
Chart1->Series[0]->Clear();
Chart1->View3D = true; // 是否以3D形式显示
Chart1->TopAxis->Title->Caption = "X TEST TEST"; Chart1->BottomAxis->Title->Caption = "Y TESTTES ";
Chart1->Title->Text->Strings[0] = "hi";
for (int i = 1; i <= 12; i )
{
Chart1->Series[0]->AddXY(i , i);
}
在各种图形之间切换
首先 delete Chart1->Series[0] 删除原来的图形对象,再重新生成,如:
delete Chart1->Series[0];
Chart1->AddSeries(new TBarSeries(Chart1));
Chart1->View3D = true;
Chart1->TopAxis->Title->Caption = "X TEST TEST";
Chart1->BottomAxis->Title->Caption = "Y TESTTES ";
for (int i = 1; i <= 12; i )
{
Chart1->Series[0]->AddXY(i , i);
}【全文结束】
delphiTeeChart的各种属性

TeeChart使用指南
TeeChart控件介绍
TeeChart Pro ActiveX是西班牙Steema SL公司开发的图表类控件,主要用来生成各种复杂的图表。熟悉Delphi和C++ Builder的编程人员对它不会陌生,因为在Delphi和C++ Builder里包括了TeeChart的VCL版本。
TeeChart使用目的
如果你需要在程序中制作曲线图、条状图、饼状图等等,使用这个控件都将是你的明智选择。它因为是已经被封装好的产品,所以使用方便,可控性强,不过有的时候会有点小BUG。最好能找到源码,并自己打几个补丁。
TeeChart名词解释
Series
Axis
Scales
Line
Bar
Pie
TeeChart配置说明
ChartSeries(序列) : 在一个图表中可以有一个或多个序列,每个序列可以有不同的显示类型,如Line、Bar、Pie等等。
Add… 添加新的序列
Fast Line(TFastLineSeries简单曲线图)、
Line(TLineSeries 3D曲线图)、
Bar(TBarSeries竖条状图)、
Horiz. Bar(THorizBarSeries横条状图)
Area(TAreaSeries 区域图)、
Point(TPointSeries 点状图)、
Pie(TPieSeries 饼状图)、
Shape(TChartShape 实体图)、
Gantt(TGanttSeries 甘特图)、
Arrow(TArrowSeries 箭头图)、
Bubble(TBubbleSeries 泡泡图)
SeriesFormat:修改序列的格式
SeriesPoint:修改序列中点的样子
SeriesGeneral:对序列的配置,包括Axis,Legend,Formats,Cursor。
SeriesMarks:是否显示序列中每个点的值。
SeriesData Source:数据源。可以采用No Data,Random Values,Function。
Title… 修改序列的名称。
Change… 修改序列的类型,可以从Line改变成Bar或者Pie。
ChartGeneral:一些基本的参数设置。
Print Priview…:打印及打印预览
Export…:输出
Margins:页边空白
Allow Zoom:允许缩放
Animated Zoom:缩放过程是否是动态的,还是一次成功。(如果图的点太多时,可以打开这个功能)
Allow Scroll:滚动条
ChartAxis : 控制图表坐标轴(上、下、左、右、深)的属性
Show Axis:是否显示坐标轴
ChartAxisScales:调整坐标轴的比例
Automatic:可以自动处理最大与最小值,也可以手工设置。
Change…:可以自动处理增量,也可以手工设置。
Logarithmic:对数的
Inverted:反向的
ChartAxisTitle:设置坐标轴的标题
Title:标题
Angle:标题的角度
Size:标题的宽度
Font…:标题的字体
ChartAxisLabels:设置坐标轴的标签
Titles :
ChartLegend(图例):图表中的一个长方形的用来显示图例标注的区域。可以标注Series的名称或者Series中的项目和数值。
Visible
Back Color
Font
Frame
Position
Margin
Legend Style
Text Style
Resize Chart
Inverted
%Top Pos
%Color Width
Dividing Lines…
Shadow
ChartPanel (面板):Panel可以设置图表的背景。可以使用渐变的颜色或者图像文件作为整个图表的背景
Bevel Inner (Bevel Innner ) Width
Bevel Outer (Bevel Outer) Width
Back Image:图表的背景图
Style:(Stretch伸展, Tile瓦片, Center居中)
Inside:只显示在背后壁上
Panel Color:Panel的Inner的颜色
Border:给控件加边界
Gradient(梯度):梯度显示颜色
Visible、Start Color…、End Color…、
Direction(方向):上下、左右、从中间

ChartPaging :图表有几页组成
Points Per Page(每页显示几个点):0为所有的点显示在一页,其他按数字处理。
Scale Last Page:最后一页按比例显示,使之充满整个图表。

ChartWalls(壁)
Left Walls:Y轴的平面
Bottom Walls:X轴的平面
Back Walls:背后的平面
Pattern…(模式):=(Solid实心,None无,Horizontal竖条纹,Vertical横条纹,
Diagonal对角线,Back.Diagonal反向对角线,Cross十字线,DiagonalCross对角十字线);
Border…(边线):=(Solid实线, Dash划线, Dot点,
Dash Dot线点, Dash Dot Dot线点点, Small Dots小点)
Transparent (透明)

Chart3D
3Dimensions(维):是否3维显示
Orthogonal(直角的):3维显示为直角显示,则Elevation,Rotaion,Perspective被屏蔽
ZoomText:坐标数字与图形一起缩放
Zoom:图形的缩放
Rotaion(旋转):关闭Orthogonal后,可以在Y轴上旋转
Elevation(正视图) :关闭Orthogonal后,可以在X轴上旋
Horiz. Offset:在X轴移动图形
Vert. Offset:在Y轴移动图形
Perspective(透视) :关闭Orthogonal后,将焦点沿Z轴移动。

TeeChart使用实例
// AddPages
NewTabSheet := TTabSheet.Create(pgMain);
with NewTabSheet do
begin
Parent := pgMain;
PageControl := pgMain;
Tag := Ord(CountTypeIndex);
Caption := arrCountType[CountTypeIndex];
end;
// AddCharts
NewChart := TChart.Create(NewTabSheet);
with NewChart do
begin
Parent := NewTabSheet;
Title.Text.Add('网间结算' + arrCountType[CountTypeIndex] + '/天分布图');
LeftAxis.Title.Caption := arrCountType[CountTypeIndex];
BottomAxis.Title.Caption := '话单日期';
Legend.Visible := sbLegend.Down;
Legend.Alignment := laBottom;
Legend.LegendStyle := lsSeries;
View3D := sb3D.Down;
Width := NewTabSheet.Width;
Height := NewTabSheet.Height;
end;
// ClearSeries
AChart.Series[SeriesIndex].Free;
// AddSeries
NewSeries := TLineSeries.Create(AChart);
NewSeries.Title := ANameList.Strings[SeriesIndex];

NewSeries.Marks.Visible :=True;
AChart.AddSeries(NewSeries);
// AddNameForSeries
AChart.SeriesList[SeriesIndex].Title:= NewName;
// ShowSeries
AChart.Series[SeriesIndex].Active := True;
// EmptySeries
AChart.Series[SeriesIndex].Clear;
// FillSeries
AChart.Series[SeriesIndex].AddXY();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息