Delphi中的TChart使用用法文档格式.docx

上传人:b****6 文档编号:21685131 上传时间:2023-01-31 格式:DOCX 页数:11 大小:99.05KB
下载 相关 举报
Delphi中的TChart使用用法文档格式.docx_第1页
第1页 / 共11页
Delphi中的TChart使用用法文档格式.docx_第2页
第2页 / 共11页
Delphi中的TChart使用用法文档格式.docx_第3页
第3页 / 共11页
Delphi中的TChart使用用法文档格式.docx_第4页
第4页 / 共11页
Delphi中的TChart使用用法文档格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

Delphi中的TChart使用用法文档格式.docx

《Delphi中的TChart使用用法文档格式.docx》由会员分享,可在线阅读,更多相关《Delphi中的TChart使用用法文档格式.docx(11页珍藏版)》请在冰豆网上搜索。

Delphi中的TChart使用用法文档格式.docx

此外,TChart还提供了渐变的背景支持,通过Gradient控制:

Chart1.Gradient.Visible:

=True;

Chart1.Gradient.Direction:

=gdFromTopLeft;

Chart1.Gradient.StartColor:

Chart1.Gradient.EndColor:

=clYellow;

4.TChart的3D效果如何控制?

TChart提供了View3D

属性,控制是否使用3D效果,View3dWalls属性控制是否显示左侧的3D墙效果5.如何不

显示图表控件生成图表?

很遗憾,TChart是一个Windows窗体控件,必须依附一个窗体或Windows控件才能使用。

如果要不显示TChart的话,可以将TChart的Visible属性设为False

来使用。

下面的例子创建了一个隐藏的TChart来生成图表:

var

Chart:

TChart;

S:

TChartSeries;

TmpFile:

string;

Chart:

=TChart.Create(nil);

try

Chart.Parent:

=Application.MainForm;

Chart.Visible:

=False;

Chart.Title.Text.Text:

测试图表'

S:

=TBarSeries.Create(Chart);

Chart.AddSeries(S);

S.Title:

嘿嘿'

S.AddXY(1,56,'

一月'

S.AddXY(2,67,'

二月'

clYellow);

S.AddXY(3,34,'

三月'

clBlue);

S.AddXY(4,78,'

四月'

Chart.View3D:

Chart.BackColor:

Chart.Gradient.StartColor:

Chart.Gradient.EndColor:

Chart.Gradient.Visible:

TmpFile:

=Application.ExeName+'

.bmp'

Chart.SaveToBitmapFile(TmpFile);

Image1.Picture.LoadFromFile(TmpFile);

finally

Chart.Free;

TChart使用经验小结1、问题:

通过Addxy方法给TChart添加标记(Mark)时,发现在TChart的横坐标会随着Mark而变化,后来发现通过以下方法可避免这种情况:

双击

TChart,点击Axis->

toporbottom->

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......privateNowindex:

Integer;

Cantuo:

boolean;

........procedure

TfrmMain.Chart1ClickSeries(Sender:

TCustomChart;

Series:

ValueIndex:

Integer;

Button:

TMouseButton;

Shift:

TShiftState;

X,Y:

Integer);

NowIndex:

=ValueIndex;

procedureTfrmMain.Chart1MouseDown(Sender:

TObject;

Button:

TMouseButton;

beginCantuo:

=true;

procedure

TfrmMain.Chart1MouseUp(Sender:

Integer);

=false;

procedureTfrmMain.Chart1MouseMove(Sender:

TShiftState;

beginifCantuothenbeginSeries1.yValue[NowIndex]:

=

Series1.yScreenToValue(y);

这里即实现了可以在图表中拖动某一个点使其在纵轴上

变化位置Tchart分析报告1Tchart分析报告1.1[概述]TChart是delphi里面一个标准的图形显示控件。

它可以静态设计(atdesigntime)也可以动态生成。

1.2[继承关系]TObjectTPersistentTComponentTControlTCustomControlTWedgetControl

TChartTCustomPanel1.3[tips]1.3.1ProVersion支持Bezier,Contour,Radar和point3D曲线1.3.2支持jpeg文件的导出1.3.3Chart中的Series可以连接到Table,Query,RemoteDataset(其他数据集)1.3.4TChart里的series的active属性可以实现对已绘制图形的显示或者隐藏1.3.5在TChart中,tchartSeries是所有具体series的父类,没有画出什么来的,用一个具体的series类来创建就可以了,比如用TLineSeries、TPieSeries、TPointSeries、TPointSeries等等都行1.3.6TTeeFunctionComponent可以实现在同一个TChart里面,一个Serries对另一个Serries的统计1.4[问题极其使用技巧]1.4.1TChart中如何实现只有Y轴的放大与缩

小功能?

设置BottomAxis或者LeftAxis的Automatic:

=false并同时设置Minimum,Maximum属性1.4.2如何固定TChart中的坐标,不使TChart中的坐标跟随Series的变化而变化?

//设置底座标withmyChart.BottomAxisdobeginAutomatic:

Minimum:

=0;

LabelStyle:

=talText;

end;

//设置左坐标withmyChart.LeftAxisdobegin

Automatic:

Minimum:

Title.Angle:

=270;

Title.Font:

=Self.Font;

Title.Font.Charset:

=ANSI_CHARSET;

Title.Font.Name:

='

@宋体'

Grid.Visible:

//设置右坐标withmyChart.RightAxisdobeginAutomatic:

Title.Font:

Title.Font.Charset:

Title.Caption:

累计百分比(%)'

Maximum:

=100;

1.4.3

如何删除一个图形中的一个点?

使用Series的delete方法1.4.4如何修改一个点的X或者Y值?

LineSeries1.YValue[3]:

=27.1;

{InBubble

Series}BubbleSeries1.RadiusValues.Value[8]:

=8.1;

{InPie

Series}PieSeries1.PieValues.Value[3]:

=111;

1.4.5如果横坐标是时间(日期),

如何进行设置?

{First,youneedtosettheDateTimepropertytoTrueinthedesiredXand/orY

valueslist.}LineSeries1.XValues.DateTime:

=True;

{Second,usethesameabovedescribed

methods,butgivethevaluesasDate,TimeorDateTime

values}LineSeries1.AddXY(EncodeDate(1996,1,23),25.4,'

Barcelona'

clGreen);

1.4.6

如何在chart中画出的曲线某个点上标记出该点的值?

Series.Marks.Visible:

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.1Line(TLineSeries)1.5.2FastLine

(TFastLineSeries)相对Line来说,它损耗了某些属性从而来实现快速绘制1.5.3Bar(TBarSeries)1.5.4Horizontalbar(THorizBarSeries)1.5.5Area

(TAreaSeries)1.5.6Point(TPointSeries)1.5.7Pie(TPieSeries)1.5.8

Arrow(TArrowSeries)1.5.9Bubble(TBubbleSeries)1.5.10Gantt

(TGanttSeries)1.5.11Sharp(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)ProcedureScroll(ConstOffset:

Double;

CheckLimits:

Boolean);

例子如下:

Chart1.BottomAxis.Scroll(1000,

True);

这段代码也等同于WithChart1.BottomAxisdoBeginAutomatic:

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.VarMySeries:

TBarSeries;

MySeries:

TBarSeries.Create(Self);

MySeries.ParentChart:

=Chart1;

2.Chart1.AddSeries(TBarSeries.Create(Self));

3.VarMyClass:

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.3SerriesCount

属性获得SeriesList中Series的个数1.9.4隐藏TChart中的Series有三种方法,但是效果不等价1.Series1.Active:

=False;

仅仅隐藏,当设置为true的时候还可以显示出来2.Series1.ParentChart:

=nil;

隐藏,重新设置ParentChart为TChart时候可以显示3.Series1.Free;

删除了Series.不可以恢复1.9.5TChart中的数据排序WithSeries1dobeginYValues.Order:

=loAscending;

YValues.Sort;

Repaint;

Ø

定位一个点(Loacateapoint)Series1.XValues.Locate(123);

XValue和YValue都拥有的属性Total,TotalABS,MaxValue,MinValueteechart笔记(Delphi)来自:

bobo日期:

2006-12-423:

09:

07全文阅读:

loading...分类:

学习札记1.series的方法1.1ColorRange设定一定范围的点和线的颜色。

procedureColorRange(AValueList:

TChartValueList;

Const

FromValue,ToValue:

Double;

AColor:

TColor);

其中:

TheTChartValueListcomponentisthe

containerofpointvalues.EachSeriescomponenthasoneormorevalueslists.The

XValuesandYValuespropertiesareTChartValueListcomponents.可以是XValues或YValues;

FromValue,ToValue是范围。

AColor是点的颜色。

UnitTeEngineDescriptionThis

methodwillchangetheColorofaspecifiedrangeofpoints.TheFromValueandToValue

parametersarethebeginningandendofthespecifiedAValueListrange.AValueListcanbeany

SeriesValueListsuchas:

XValues,YValues,etc.对某一特定的点:

可以用series.valuecolor[index]属性propertyValueColor[Index:

Integer]:

TColor;

UsetheValueColor

propertytogetorsettheColorofapointataparticularposition.Indexgivesthepositionofthe

point,where0isthefirst,1isthesecond,andsoon.不过这两个方法都会导致线的颜色也会改

变:

改变的模式是若下一点出界,则从此点到下一点的连线的颜色变为指定点的颜色。

用这种方法可以改变各个点的形状,result即是具体点的形状。

functionTForm1.Series1GetPointerStyle(Sender:

Integer):

TSeriesPointerStyle;

beginifValueIndexmod2=0thenresult:

=psRectangle

elseresult:

=psTriangle;

1.2CalcXPosValue把某一轴X/Y轴的值,转化为窗体的像素值

(整型)。

CalcXPosValue(ConstValue:

Double):

UnitTeEngineDescriptionReturnsthe

pixelScreenHorizontalcoordinateofthespecifiedValue.forexample:

procedureTForm1.Chart1AfterDraw(Sender:

TObject);

vartmp:

tmp:

=Series1.CalcPosValue(123);

withChart1.CanvasdoRectangle(tmp-5,tmp-5,tmp

5,tmp5);

1.3画水平直线Chart1AfterDraw的时间中ProcedureTForm1.DBChart1AfterDraw(Sender:

begindrawLimits(ChrtNum,width:

integer;

Value:

color:

drawLimits(ChrtNum,width:

TColor);

varPixValue:

integer;

beginwithdbcht1.CanvasdobeginPixValue:

seriesx.CalcYPosValue(Value);

if(PixValue<

dbcht1.ChartRect.Top)or

(PixValue>

dbcht1.ChartRect.Bottom)then//判断是否已经超出dbcht1.ChartRect的范围。

Pen.Color:

=dbcht1.ColorelsePen.Color:

=color;

Pen.Width:

=width;

MoveTo(dbcht1.ChartRect.Left,PixValue);

LineTo(dbcht1.ChartRect.Right,PixValue);

1.4通过函数function来画直线/各种自定义曲线;

series|dataSource|function.在objecttreeView对象观察器中series1|TeeFunction1的OnCalculate事件中添加公式procedureTForm1.TeeFunction1Calculate(Sender:

TCustomTeeFunction;

constx:

vary:

Double);

beginy:

=50;

//y:

=Sin(x/10);

1.5取消chart的网格在chart|axis|Ticks|grid…中操作,此操作针对某一轴而言,如leftaxis,对于bottomaxis要选择它再操作。

1.6marktips显示数据标签的chart工具。

设定自定义的标签的方法:

设定一个单元局部变量MarkText:

string在chart的onMouseMove中添加事件。

procedureTfrmVChart.dbcht1MouseMove(Sender:

vartmp:

begintmp:

=SeriesX.Clicked(x,y);

//返回该点的所在的series上序号,从0开始。

iftmp=-1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1