TeeChart使用心得(一)
TeeChart 使用心得(一) TeeChart 是Delphi 里面一个标准的图形显示控件。它可以静态设计(at design time )也可以动态生成。下面是我在使用过程中的一些心得体会,比较杂,但也许对你有用。
TeeChart 的继承关系
?
TObject ?
TPersistent ?
TComponent ?
TControl ?
TCustomControl ?
TWedgetControl ?
TChart ? TCustomPanel
TeeChart 常见问题及使用技巧
1、TChart 中如何实现只有Y 轴的放大与缩小功能?
? 设置BottomAxis 或者LeftAxis 的Automatic:=false 并同时设置
Minimum,Maximum 属性
2、如何固定TChart 中的坐标,不使TChart 中的坐标跟随Series 的变化而变化? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 //设置底座标
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;
https://www.360docs.net/doc/9d14648037.html,:='@宋体';
Grid.Visible := False;
end;
19 20 21 22 23 24 25 26 27 28 29 //设置右坐标
with myChart.RightAxis do
begin
Automatic:=false;
Title.Font:=Self.Font;
Title.Font.Charset:=ANSI_CHARSET;
https://www.360docs.net/doc/9d14648037.html,:='@宋体';
Title.Caption:='累计百分比(%)';
Maximum:=100;
Minimum:=0;
end;
3、如何删除一个图形中的一个点?
使用Series 的delete 方法
4、如何修改一个点的X 或者Y 值?
1 2 3 4 5 LineSeries1.YValue[3] := 27.1 ;
{In Bubble Series}
BubbleSeries1.RadiusValues.Value[ 8 ] := 8.1 ;
{In Pie Series}
PieSeries1.PieValues.Value[ 3 ] := 111 ;
5、如果横坐标是时间(日期),如何进行设置?
1 2 3 4 {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 );
6、如何在chart 中画出的曲线某个点上标记出该点的值?
1 2 Series.Marks.Visible:=true;
Series.Marks.Style:=smsValue;
7、如何设置横轴或者纵轴的增长率?
1 2 Chart.BottomAxis.Increment := DataTimeStep[ dtOneHour ] ;
Chart.RightAxis.Increment := 1000;
8、如何对图象进行缩放?
?TChart的ZoomRect或者ZoomPercent方法(Pie图可能不支持缩放)TeeChart可以绘制的图形:
?Line ( TLineSeries)
?FastLine (TFastLineSeries) 相对Line来说,它损耗了某些属性从而来实现快速绘制
?Bar (TBarSeries)
?Horizontal bar (THorizBarSeries)
?Area (TAreaSeries)
?Point (TPointSeries)
?Pie (TPieSeries)
?Arrow (TArrowSeries)
?Bubble (TBubbleSeries)
?Gantt (TGanttSeries)
?Sharp (TChartShape)
TeeChart的实时绘制
实时绘制对机器性能要求比较高,因此我们在编程的时候要注意下面几个方面:?使用2D图形
?是Chart尽可能包含少的点
?如果需要,可以移除(remove)chart的legend(?????)和Title
?使用默认的字体和字体大小
?使用FastLineSeries
?使用实体(solid)画笔和画刷格式
?尽量避免使用圆形和环行bar样式
?不要使用背景图片和渐变效果样式
?把Chart的BevelInner和BevelOUter属性设置为bcNone
?如果需要,把TChart的AxisVisible属性设置为False
?把BufferedDisplay设置为false可以加速chart的重绘
滚动
TChart有4种scroll选择(AllowPanning属性),分别是不允许Scroll
( pmNone) ; 水平Scroll (pmHorizontal) ; 垂直Scroll (pmVertical) ; 水平和垂直Scroll (pmBoth)
Procedure Scroll(ConstOffset:Double; CheckLimits:Boolean);
例子如下:
1 C hart1.BottomAxis.Scroll( 1000, True );
这段代码也等同于
1 2 3 4 5 With Chart1.BottomAxis do
Begin
Automatic:=false;
SetMinMax( Minimum+1000, Maximum+1000 ); End;