📄 chart.pas
字号:
{******************************************}
{ TCustomChart & TChart Components }
{ Copyright (c) 1995-2005 by David Berneda }
{ All Rights Reserved }
{******************************************}
unit Chart;
{$I TeeDefs.inc}
interface
uses {$IFNDEF LINUX}
Windows,
{$ENDIF}
Classes, SysUtils,
{$IFDEF CLX}
QGraphics, QControls, QExtCtrls, QForms, QButtons, Types,
{$ELSE}
Graphics,
Controls,
{$IFDEF D9}
Types,
{$ENDIF}
{$IFNDEF D5}
{$IFNDEF LCL}
Buttons,
{$ENDIF}
{$ENDIF}
{$ENDIF}
TeeProcs, TeEngine, TeCanvas;
Const TeeMsg_DefaultFunctionName = 'TeeFunction'; { <-- dont translate }
TeeMsg_DefaultSeriesName = 'Series'; { <-- dont translate }
TeeMsg_DefaultToolName = 'ChartTool'; { <-- dont translate }
ChartComponentPalette = 'TeeChart'; { <-- dont translate }
TeeMaxLegendColumns = 2;
TeeDefaultLegendSymbolWidth= 20;
var AnimatedZoomFactor : Double=3.0; { controls the animated zoom "speed" }
TeeScrollKeyShift : TShiftState=[]; { keys that should be pressed to start scroll }
TeeTitleFootDistance : Integer=5; { fixed pixels distance between title/foot and chart }
TeeUseMouseWheel : Boolean=True; { use the mouse wheel to scroll the axes }
type
TCustomChartWall=class(TTeeCustomShape)
private
FAutoHide : Boolean;
FDark3D : Boolean;
FSize : Integer;
Function ApplyDark3D:Boolean;
Function GetPen:TChartPen;
Function HasGradient:Boolean;
Procedure InitColor(AColor:TColor);
Function IsColorStored:Boolean;
procedure SetAutoHide(const Value: Boolean);
Procedure SetDark3D(Value:Boolean);
Procedure SetPen(Value:TChartPen);
Procedure SetSize(Value:Integer);
Function TryDrawWall(APos1,APos2:Integer):TTeeBlend;
protected
DefaultColor : TColor;
Function ShouldDraw:Boolean;
public
Constructor Create(AOwner:TCustomTeePanel); override;
Procedure Assign(Source:TPersistent); override;
property AutoHide:Boolean read FAutoHide write SetAutoHide default False;
property Color stored IsColorStored nodefault; { 5.02 }
property Dark3D:Boolean read FDark3D write SetDark3D default True;
property Pen:TChartPen read GetPen write SetPen;
property Size:Integer read FSize write SetSize default 0;
property Transparency;
end;
TChartWall=class(TCustomChartWall)
published
property AutoHide; // 7.0
property Brush;
property Color;
property Dark3D;
property Gradient;
property Pen;
property Size;
property Transparency;
property Transparent;
property Visible default True;
end;
TChartLegendGradient=class(TChartGradient)
public
Constructor Create(ChangedEvent:TNotifyEvent); override;
published
property Direction default gdRightLeft;
property EndColor default clWhite;
property StartColor default clSilver;
end;
{ TCustomChartLegend Component }
TLegendStyle =(lsAuto,lsSeries,lsValues,lsLastValues);
TLegendAlignment=(laLeft,laRight,laTop,laBottom);
LegendException =class(Exception);
TOnGetLegendText=Procedure( Sender:TCustomAxisPanel;
LegendStyle:TLegendStyle;
Index:Integer;
Var LegendText:String) of Object;
TCustomChartLegend=class;
TLegendSymbolSize=(lcsPercent,lcsPixels);
TLegendSymbolPosition=(spLeft,spRight);
TSymbolDrawEvent=procedure(Sender:TObject; Series:TChartSeries;
ValueIndex:Integer; R:TRect) of object; // 7.0
TSymbolCalcHeight=function:Integer of object; // 7.06
TLegendSymbol=class(TPersistent)
private
FContinuous : Boolean;
FDefaultPen : Boolean;
FGradient : TTeeGradient;
FOnDraw : TSymbolDrawEvent; // 7.0
FPen : TChartPen;
FPosition : TLegendSymbolPosition;
FSquared : Boolean;
FVisible : Boolean;
FWidth : Integer;
FWidthUnits : TLegendSymbolSize;
Procedure CanvasChanged(Sender:TObject);
procedure SetContinuous(const Value: Boolean);
procedure SetDefaultPen(const Value: Boolean);
Procedure SetGradient(Value:TTeeGradient);
procedure SetPen(const Value: TChartPen);
Procedure SetPosition(Const Value:TLegendSymbolPosition);
procedure SetSquared(const Value: Boolean);
procedure SetVisible(const Value: Boolean);
procedure SetWidth(Const Value: Integer);
procedure SetWidthUnits(const Value: TLegendSymbolSize);
protected
CalcItemHeight : TSymbolCalcHeight;
Function CalcWidth(Value:Integer):Integer;
procedure Draw(AColor:TColor; const R:TRect);
public
Parent : TCustomTeePanel;
Constructor Create(AParent:TCustomTeePanel);
Destructor Destroy; override;
Procedure Assign(Source:TPersistent); override;
published
property Continuous:Boolean read FContinuous write SetContinuous default False;
property DefaultPen:Boolean read FDefaultPen write SetDefaultPen default True;
property Gradient:TTeeGradient read FGradient write SetGradient;
property Pen:TChartPen read FPen write SetPen;
property Position:TLegendSymbolPosition read FPosition write SetPosition default spLeft;
property Squared:Boolean read FSquared write SetSquared default False;
property Visible:Boolean read FVisible write SetVisible default True;
property Width:Integer read FWidth write SetWidth default TeeDefaultLegendSymbolWidth;
property WidthUnits:TLegendSymbolSize read FWidthUnits
write SetWidthUnits default lcsPercent;
property OnDraw:TSymbolDrawEvent read FOnDraw write FOnDraw;
end;
TTeeCustomShapePosition=class(TTeeCustomShape)
private
Function GetLeft:Integer; {$IFDEF D9}inline;{$ENDIF}
Function GetTop:Integer; {$IFDEF D9}inline;{$ENDIF}
function IsCustomStored:Boolean;
procedure SetCustomPosition(Const Value:Boolean);
procedure SetLeft(Const Value: Integer);
procedure SetTop(Const Value: Integer);
protected
FCustomPosition : Boolean;
{$IFDEF CLR}
public
{$ENDIF}
DefaultCustom : Boolean;
public
Procedure Assign(Source:TPersistent); override;
property CustomPosition:Boolean read FCustomPosition write SetCustomPosition stored IsCustomStored;
property Left:Integer read GetLeft write SetLeft stored FCustomPosition;
property Top:Integer read GetTop write SetTop stored FCustomPosition;
end;
TCheckBoxesStyle=(cbsCheck, cbsRadio);
TLegendTitle=class(TTeeShape)
private
FText : TStringList;
FTextAlign : TAlignment;
procedure CalcHeight;
procedure CalcShapeBounds(Const R:TRect);
procedure SetText(const Value: TStringList);
procedure SetTextAlign(const Value: TAlignment);
procedure TextChanged(Sender:TObject);
function TotalWidth:Integer;
function GetCaption: String;
procedure SetCaption(const Value: String);
protected
procedure DrawText;
public
Constructor Create(AOwner: TCustomTeePanel); override;
Destructor Destroy; override;
Procedure Assign(Source:TPersistent); override;
property Caption:String read GetCaption write SetCaption; // 7.02
published
property Text:TStringList read FText write SetText;
property TextAlignment:TAlignment read FTextAlign
write SetTextAlign default taLeftJustify;
property TextFormat; // 7.02
end;
TLegendItem=class {$IFDEF CLR}sealed{$ENDIF}
private
FAlign : Integer;
FLeft : Integer;
FSymbol : TRect;
FText : String;
FTop : Integer;
ILegend : TCustomChartLegend;
procedure SetText(const Value:String);
{$IFDEF BCB}
public
property SymbolRect:TRect read FSymbol write FSymbol;
{$ELSE}
{$IFDEF LCL}
public
property SymbolRect:TRect read FSymbol write FSymbol;
{$ENDIF}
{$ENDIF}
published
property Align:Integer read FAlign;
property Left:Integer read FLeft;
{$IFNDEF BCB}
{$IFNDEF LCL}
property SymbolRect:TRect read FSymbol write FSymbol;
{$ENDIF}
{$ENDIF}
property Text:String read FText write SetText;
property Top:Integer read FTop;
end;
TLegendItems=class {$IFDEF CLR}sealed{$ENDIF}(TList)
private
FCustom : Boolean;
ILegend : TCustomChartLegend;
function Get(Index:Integer):TLegendItem;
public
Procedure Clear; override;
property Custom:Boolean read FCustom write FCustom;
property Items[Index:Integer]:TLegendItem read Get; default;
end;
TLegendCalcSize=procedure(Sender:TCustomChartLegend; var ASize:Integer) of object;
TCustomChart=class;
TCustomChartLegend=class(TTeeCustomShapePosition)
private
FAlignment : TLegendAlignment;
FCheckBoxes : Boolean;
FCheckBoxesStyle : TCheckBoxesStyle;
FCurrentPage : Boolean;
FDividingLines : TChartHiddenPen;
FFirstValue : Integer;
FFontSeriesColor : Boolean;
FHorizMargin : Integer;
FInverted : Boolean;
FItems : TLegendItems;
FLeftPercent : Integer; // 7.06
FLegendStyle : TLegendStyle;
FMaxNumRows : Integer;
FPosUnits : TTeeUnits; // 7.06
FResizeChart : Boolean;
FSeries : TChartSeries;
FSymbol : TLegendSymbol;
FTextStyle : TLegendTextStyle;
FTitle : TLegendTitle;
FTopLeftPos : Integer;
FTopPercent : Integer; // 7.06
FVertMargin : Integer;
FVertSpacing : Integer;
{ Internal }
IColorWidth : Integer;
ILastValue : Integer;
ITotalItems : Integer;
IDrawTitle : Boolean;
Function CalcItemHeight:Integer;
Function FirstItemTop:Integer;
function GetItem(Index:Integer):TLegendItem;
Function GetLegendSeries:TChartSeries;
Function GetRectLegend:TRect;
Function GetSymbolWidth:Integer;
Function GetVertical:Boolean;
Function HasCheckBoxes:Boolean;
Procedure PrepareSymbolPen;
Procedure SetAlignment(Const Value:TLegendAlignment);
Procedure SetCheckBoxes(Const Value:Boolean);
Procedure SetCheckBoxesStyle(Const Value:TCheckBoxesStyle);
procedure SetCurrentPage(Const Value: Boolean);
Procedure SetDividingLines(Const Value:TChartHiddenPen);
Procedure SetFirstValue(Const Value:Integer);
procedure SetFontSeriesColor(const Value: Boolean);
Procedure SetHorizMargin(Const Value:Integer);
Procedure SetInverted(Const Value:Boolean);
Procedure SetLeftPercent(Const Value:Integer);
Procedure SetLegendStyle(Const Value:TLegendStyle);
Procedure SetMaxNumRows(Const Value:Integer);
Procedure SetPosUnits(Const Value:TTeeUnits);
Procedure SetResizeChart(Const Value:Boolean);
Procedure SetSeries(Const Value:TChartSeries);
Procedure SetSymbol(Const Value:TLegendSymbol);
Procedure SetSymbolWidth(Const Value:Integer);
Procedure SetTextStyle(Const Value:TLegendTextStyle);
procedure SetTitle(const Value: TLegendTitle);
Procedure SetTopLeftPos(Const Value:Integer);
Procedure SetTopPercent(Const Value:Integer);
Procedure SetVertMargin(Const Value:Integer);
Procedure SetVertSpacing(Const Value:Integer);
protected
InternalLegendStyle : TLegendStyle;
FOnCalcSize : TLegendCalcSize;
Procedure CalcLegendStyle;
Function DoMouseDown(Const x,y:Integer; PointIndex:Integer):Boolean;
Function GetGradientClass:TChartGradientClass; override;
public
NumCols : Integer;
NumRows : Integer;
ColumnWidthAuto: Boolean;
ColumnWidths : Array[0..TeeMaxLegendColumns-1] of Integer;
Constructor Create(AOwner:TCustomTeePanel); override;
Destructor Destroy; override;
Procedure Assign(Source:TPersistent); override;
Function Clicked(x,y:Integer):Integer;
Procedure DrawLegend;
Function FormattedValue(ASeries:TChartSeries; ValueIndex:Integer):String;
Function FormattedLegend(SeriesOrValueIndex:Integer):String;
Function ShouldDraw:Boolean; // 6.02
property TotalLegendItems:Integer read ITotalItems;
{ public properties }
property RectLegend:TRect read GetRectLegend;
property Vertical:Boolean read GetVertical;
{ to be published }
property Alignment:TLegendAlignment read FAlignment write SetAlignment
default laRight;
property CheckBoxes:Boolean read FCheckBoxes write SetCheckBoxes default False;
property CheckBoxesStyle:TCheckBoxesStyle read FCheckBoxesStyle write SetCheckBoxesStyle default cbsCheck;
property ColorWidth:Integer read GetSymbolWidth write SetSymbolWidth default TeeDefaultLegendSymbolWidth;
property CurrentPage:Boolean read FCurrentPage write SetCurrentPage default True;
property DividingLines:TChartHiddenPen read FDividingLines write SetDividingLines;
property FirstValue:Integer read FFirstValue write SetFirstValue default 0;
property FontSeriesColor:Boolean read FFontSeriesColor write SetFontSeriesColor default False;
property HorizMargin:Integer read FHorizMargin write SetHorizMargin default 0;
property Inverted:Boolean read FInverted write SetInverted default False;
property Item[Index:Integer]:TLegendItem read GetItem; default;
property Items:TLegendItems read FItems;
property LastValue:Integer read ILastValue; // 6.02
property LeftPercent:Integer read FLeftPercent write SetLeftPercent default 0;
property LegendStyle:TLegendStyle read FLegendStyle
write SetLegendStyle default lsAuto;
property MaxNumRows:Integer read FMaxNumRows write SetMaxNumRows default 10;
property PositionUnits:TTeeUnits read FPosUnits write SetPosUnits default muPixels;
property ResizeChart:Boolean read FResizeChart write SetResizeChart default True;
property Series:TChartSeries read FSeries write SetSeries;
property Symbol:TLegendSymbol read FSymbol write SetSymbol;
property TextStyle:TLegendTextStyle read FTextStyle
write SetTextStyle default ltsLeftValue;
property Title:TLegendTitle read FTitle write SetTitle;
property TopPercent:Integer read FTopPercent write SetTopPercent default 0;
property TopPos:Integer read FTopLeftPos write SetTopLeftPos default 10;
property VertMargin:Integer read FVertMargin write SetVertMargin default 0;
property VertSpacing:Integer read FVertSpacing write SetVertSpacing default 0;
property Visible default True;
end;
TChartLegend=class(TCustomChartLegend)
published
property Alignment;
property Bevel;
property BevelWidth;
property Brush;
property CheckBoxes;
property CheckBoxesStyle;
property Color;
property ColorWidth;
property CurrentPage; // 5.02
property CustomPosition;
property DividingLines;
property FirstValue;
property Font;
property FontSeriesColor;
property Frame;
property Gradient;
property HorizMargin;
property Inverted;
property Left;
property LeftPercent;
property LegendStyle;
property MaxNumRows;
property PositionUnits; // 7.06
property ResizeChart;
property Shadow;
property ShapeStyle;
property Symbol;
property TextStyle;
property Title;
property Top;
property TopPercent;
property TopPos;
property Transparency;
property Transparent;
property VertMargin;
property VertSpacing;
property Visible;
end;
TChartTitle=class(TTeeCustomShapePosition)
private
FAdjustFrame : Boolean;
FAlignment : TAlignment;
FText : TStrings;
IOnTop : Boolean;
Function GetShapeBounds:TRect;
Procedure SetAdjustFrame(Value:Boolean);
Procedure SetAlignment(Value:TAlignment);
Procedure SetText(Value:TStrings);
function GetCaption: String;
procedure SetCaption(const Value: String);
public
Constructor Create(AOwner: TCustomTeePanel); override;
Destructor Destroy; override;
Procedure Assign(Source:TPersistent); override;
procedure Clear;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -