home *** CD-ROM | disk | FTP | other *** search
- unit TeeAxisLabelTool;
-
- interface
-
- Uses Classes, SysUtils, TeeProcs, TeEngine, Chart, TeeTools;
-
- { TAxisLabelTool. Example of a Custom Chart Tool. }
- { This custom tool is used to change Axis labels.
-
- If axis labels are bigger than 1000, the tool
- appends "K" (thousands) to the label.
- If the label is bigger than 100000, then it shows
- "M" (millions).
-
- Example: 2000 is displayed as "2K"
- 4000000 is displayed as "4M".
-
- This tool is useful to reduce the space used by
- big axis label values.
- }
- type
- TAxisLabelTool=class(TTeeCustomToolAxis)
- private
- FMillion: String;
- FThousand: String;
- procedure SetMillion(const Value: String);
- procedure SetThousand(const Value: String);
- protected
- procedure SetParentChart(const Value: TCustomAxisPanel); override;
- Procedure OnGetLabel( Sender:TChartAxis; Series:TChartSeries;
- ValueIndex:Integer; Var LabelText:String);
- public
- Constructor Create(AOwner:TComponent); override;
- class Function Description:String; override;
- published
- property MillionText:String read FMillion write SetMillion;
- property ThousandText:String read FThousand write SetThousand;
- end;
-
- implementation
-
- { Here it comes the tool code... }
-
- { TAxisLabelTool }
- constructor TAxisLabelTool.Create(AOwner: TComponent);
- begin
- inherited;
- FMillion:='M';
- FThousand:='K';
- end;
-
- class function TAxisLabelTool.Description: String;
- begin
- result:='Axis Label';
- end;
-
- procedure TAxisLabelTool.OnGetLabel(Sender: TChartAxis;
- Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
- var tmp : Double;
- tmpSt : String;
- begin
- if Active and Assigned(Axis) and (Sender=Axis) then
- begin
- try
- tmpSt:=LabelText;
- While Pos(ThousandSeparator,tmpSt)>0 do
- Delete(tmpSt,Pos(ThousandSeparator,tmpSt),1);
- tmp:=StrToFloat(tmpSt);
- if tmp>=100000 then LabelText:=FormatFloat('0.#',tmp/1000000)+MillionText
- else
- if tmp>=1000 then LabelText:=FormatFloat('0.#',tmp/1000)+ThousandText;
- except
- on EConvertError do ;
- end;
- end;
- end;
-
- procedure TAxisLabelTool.SetMillion(const Value: String);
- begin
- if FMillion<>Value then
- begin
- FMillion:=Value;
- if Assigned(ParentChart) then ParentChart.Invalidate;
- end;
- end;
-
- procedure TAxisLabelTool.SetParentChart(const Value: TCustomAxisPanel);
- begin
- inherited;
- if Assigned(ParentChart) then ParentChart.OnGetAxisLabel:=OnGetLabel;
- end;
-
- procedure TAxisLabelTool.SetThousand(const Value: String);
- begin
- if FThousand<>Value then
- begin
- FThousand:=Value;
- if Assigned(ParentChart) then ParentChart.Invalidate;
- end;
- end;
-
- initialization
- { "register" the custom tool to show it at the editor tool gallery }
- RegisterTeeTools([TAxisLabelTool]);
- finalization
- UnRegisterTeeTools([TAxisLabelTool]);
- end.
-