home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Delphi Component Library }
- { Logarithmic Labels Demo }
- { Copyright (c) 1996 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit LogLab;
- {$P-}
-
- interface
-
- { This form shows how custom Axis labels can be specified }
- { The Chart.OnGetNextAxisLabel event is used to supply the axis with
- custom label positions and values. }
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, TeeProcs, TeEngine, Chart, Series, StdCtrls, Buttons;
-
- type
- TLogLabelsForm = class(TForm)
- Chart1: TChart;
- Series1: TFastLineSeries;
- Panel1: TPanel;
- BitBtn2: TBitBtn;
- Memo1: TMemo;
- procedure FormCreate(Sender: TObject);
- procedure Chart1GetNextAxisLabel(Sender: TChartAxis;
- LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
- procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
- ValueIndex: Longint; var LabelText: string);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- implementation
-
- {$R *.DFM}
-
- procedure TLogLabelsForm.FormCreate(Sender: TObject);
- begin
- { Axis settings }
- Chart1.BottomAxis.Logarithmic:=True;
- Chart1.BottomAxis.TickOnLabelsOnly:=True;
- Chart1.BottomAxis.SetMinMax( 10.0, 1000);
- Chart1.LeftAxis.Logarithmic:=True;
- Chart1.LeftAxis.TickOnLabelsOnly:=True;
- Chart1.LeftAxis.SetMinMax( 10.0, 1000);
-
- { adding XY values to Series1 }
- Series1.XValues.DateTime:=False;
- Series1.AddXY( 100, 100, '', clTeeColor );
- Series1.AddXY( 500, 200, '', clTeeColor );
- Series1.AddXY( 800, 300, '', clTeeColor );
- Series1.AddXY( 200, 200, '', clTeeColor );
- end;
-
- { OnGetNextAxisLabel event is used to supply Label POSITIONS (not text) }
- procedure TLogLabelsForm.Chart1GetNextAxisLabel(Sender: TChartAxis;
- LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
- var tmpValue:Double;
- begin
- if (Sender = Chart1.BottomAxis) or { only for these axis }
- (Sender = Chart1.LeftAxis) then
- begin
- tmpValue:=LabelValue;
- case LabelIndex of
- 0 : tmpValue := 10;
- 1 : tmpValue := 20;
- 2 : tmpValue := 30;
- 3 : tmpValue := 40;
- 4 : tmpValue := 50;
- 5 : tmpValue := 60;
- 6 : tmpValue := 70;
- 7 : tmpValue := 80;
- 8 : tmpValue := 90;
- 9 : tmpValue := 100;
- 10 : tmpValue := 200;
- 11 : tmpValue := 300;
- 12 : tmpValue := 400;
- 13 : tmpValue := 500;
- 14 : tmpValue := 600;
- 15 : tmpValue := 700;
- 16 : tmpValue := 800;
- 17 : tmpValue := 900;
- 18 : tmpValue := 1000;
- 19 : tmpValue := 2000;
- end;
- { set the desired LabelValue }
- LabelValue:=MaxDouble(LabelValue,tmpValue);
- Stop := False; { continue until no more labels }
- end;
- end;
-
- { OnGetAxisLabel event is used to supply Label TEXT (not positions) }
- procedure TLogLabelsForm.Chart1GetAxisLabel(Sender: TChartAxis;
- Series: TChartSeries; ValueIndex: Longint; var LabelText: string);
-
- Function MyLabelValue(Const Value:Double):String;
- begin
- result:=FormatFloat(Sender.AxisValuesFormat,Value);
- end;
-
- begin
- if ( Sender = Chart1.BottomAxis ) then { only for bottom axis }
- With Sender do
- begin
- { In this demo, we want only these labels, not all labels }
- if ( LabelText<>MyLabelValue(10) ) and
- ( LabelText<>MyLabelValue(100) ) and
- ( LabelText<>MyLabelValue(1000) ) and
- ( LabelText<>MyLabelValue(10000) ) then
- LabelText:='';
- end;
- end;
-
- end.
-