home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / RUNIMAGE / DELPHI30 / DEMOS / TEECHART / LOGLAB.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-04  |  3.7 KB  |  120 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Logarithmic Labels Demo                     }
  4. { Copyright (c) 1996 by David Berneda         }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit LogLab;
  8. {$P-}
  9.  
  10. interface
  11.  
  12. { This form shows how custom Axis labels can be specified }
  13. { The Chart.OnGetNextAxisLabel event is used to supply the axis with
  14.   custom label positions and values. }
  15.  
  16. uses
  17.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  18.   ExtCtrls, TeeProcs, TeEngine, Chart, Series, StdCtrls, Buttons;
  19.  
  20. type
  21.   TLogLabelsForm = class(TForm)
  22.     Chart1: TChart;
  23.     Series1: TFastLineSeries;
  24.     Panel1: TPanel;
  25.     BitBtn2: TBitBtn;
  26.     Memo1: TMemo;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure Chart1GetNextAxisLabel(Sender: TChartAxis;
  29.               LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  30.     procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  31.       ValueIndex: Longint; var LabelText: string);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TLogLabelsForm.FormCreate(Sender: TObject);
  43. begin
  44.   { Axis settings }
  45.   Chart1.BottomAxis.Logarithmic:=True;
  46.   Chart1.BottomAxis.TickOnLabelsOnly:=True;
  47.   Chart1.BottomAxis.SetMinMax( 10.0, 1000);
  48.   Chart1.LeftAxis.Logarithmic:=True;
  49.   Chart1.LeftAxis.TickOnLabelsOnly:=True;
  50.   Chart1.LeftAxis.SetMinMax( 10.0, 1000);
  51.  
  52.   { adding XY values to Series1 }
  53.   Series1.XValues.DateTime:=False;
  54.   Series1.AddXY( 100, 100, '', clTeeColor );
  55.   Series1.AddXY( 500, 200, '', clTeeColor );
  56.   Series1.AddXY( 800, 300, '', clTeeColor );
  57.   Series1.AddXY( 200, 200, '', clTeeColor );
  58. end;
  59.  
  60. { OnGetNextAxisLabel event is used to supply Label POSITIONS (not text) }
  61. procedure TLogLabelsForm.Chart1GetNextAxisLabel(Sender: TChartAxis;
  62.   LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  63. var tmpValue:Double;
  64. begin
  65.   if (Sender = Chart1.BottomAxis) or  { only for these axis }
  66.      (Sender = Chart1.LeftAxis) then
  67.     begin
  68.       tmpValue:=LabelValue;
  69.       case LabelIndex of
  70.         0 : tmpValue := 10;
  71.         1 : tmpValue := 20;
  72.         2 : tmpValue := 30;
  73.         3 : tmpValue := 40;
  74.         4 : tmpValue := 50;
  75.         5 : tmpValue := 60;
  76.         6 : tmpValue := 70;
  77.         7 : tmpValue := 80;
  78.         8 : tmpValue := 90;
  79.         9 : tmpValue := 100;
  80.         10 : tmpValue := 200;
  81.         11 : tmpValue := 300;
  82.         12 : tmpValue := 400;
  83.         13 : tmpValue := 500;
  84.         14 : tmpValue := 600;
  85.         15 : tmpValue := 700;
  86.         16 : tmpValue := 800;
  87.         17 : tmpValue := 900;
  88.         18 : tmpValue := 1000;
  89.         19 : tmpValue := 2000;
  90.       end;
  91.       { set the desired LabelValue }
  92.       LabelValue:=MaxDouble(LabelValue,tmpValue);
  93.     Stop := False; { continue until no more labels }
  94.   end;
  95. end;
  96.  
  97. { OnGetAxisLabel event is used to supply Label TEXT (not positions) }
  98. procedure TLogLabelsForm.Chart1GetAxisLabel(Sender: TChartAxis;
  99.   Series: TChartSeries; ValueIndex: Longint; var LabelText: string);
  100.  
  101.   Function MyLabelValue(Const Value:Double):String;
  102.   begin
  103.     result:=FormatFloat(Sender.AxisValuesFormat,Value);
  104.   end;
  105.  
  106. begin
  107.   if ( Sender = Chart1.BottomAxis ) then { only for bottom axis }
  108.   With Sender do
  109.   begin
  110.     { In this demo, we want only these labels, not all labels }
  111.     if ( LabelText<>MyLabelValue(10) ) and
  112.        ( LabelText<>MyLabelValue(100) ) and
  113.        ( LabelText<>MyLabelValue(1000) ) and
  114.        ( LabelText<>MyLabelValue(10000) ) then
  115.          LabelText:='';
  116.   end;
  117. end;
  118.  
  119. end.
  120.