home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / UAXISLAB.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.9 KB  |  136 lines

  1. {****************************************}
  2. {    TeeChart. TChart Component          }
  3. { Copyright (c) 1995,96 by David Berneda }
  4. {    All Rights Reserved                 }
  5. {****************************************}
  6. unit Uaxislab;
  7.  
  8. interface
  9.  
  10. { This Sample Project shows how to set the Axis Labels at specific Axis
  11.   positions.
  12.   The key is the Chart.OnGetNextAxisLabel event.
  13.   This event is called continuosly for each Axis Label until user decides
  14.   to stop.
  15.   At each call, you can specify the exact Axis value where a Label must be
  16.   drawn.
  17.  
  18.   In this example, this event is used to set the BottomAxis labels to the
  19.   first (1) day in month:   1/1/96,  2/1/96, 3/1/96..... 12/1/96
  20.  
  21.   This don't needs necessarily to be datetime values.
  22.   You can also set the Axis Labels in non-datetime axis.
  23.  
  24.   WARNING:
  25.     Remember to set the Stop boolean variable to TRUE when no more labels are
  26.     needed.
  27.     Remember also that using this event will NOT calculate Label used space or
  28.     any Font size adjustment.
  29.     TeeChart Axis will draw all labels you specify.
  30. }
  31. uses
  32.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  33.   Forms, Dialogs, Chart, Series, ExtCtrls, StdCtrls, Teengine, Buttons,
  34.   TeeProcs;
  35.  
  36. type
  37.   TAxisLabelsForm = class(TForm)
  38.     Chart1: TChart;
  39.     LineSeries1: TLineSeries;
  40.     Panel1: TPanel;
  41.     RadioGroup1: TRadioGroup;
  42.     PointSeries1: TPointSeries;
  43.     BitBtn3: TBitBtn;
  44.     Memo1: TMemo;
  45.     procedure FormCreate(Sender: TObject);
  46.     procedure RadioGroup1Click(Sender: TObject);
  47.     procedure Chart1GetNextAxisLabel(Sender: TChartAxis;
  48.       LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  49.   private
  50.     { Private declarations }
  51.   public
  52.     { Public declarations }
  53.     DefaultLabels:Boolean;
  54.   end;
  55.  
  56. implementation
  57.  
  58. {$R *.DFM}
  59.  
  60. procedure TAxisLabelsForm.FormCreate(Sender: TObject);
  61. var t:Longint;
  62. begin
  63.   DefaultLabels:=False;  { <-- boolean variable to show or not the demo }
  64.  
  65.   LineSeries1.Clear;
  66.   PointSeries1.Clear;
  67.   for t:=1 to 100 do
  68.   Begin
  69.     LineSeries1.AddXY( Date+t, 200+Random(700),'',clTeeColor);  { <-- some random points }
  70.     PointSeries1.AddXY( Date+t, 200+Random(700),'',clTeeColor);
  71.   end;
  72. end;
  73.  
  74. procedure TAxisLabelsForm.RadioGroup1Click(Sender: TObject);
  75. begin
  76.  { Choose between default and custom labeling. }
  77.   DefaultLabels:=RadioGroup1.ItemIndex=0;
  78.   Chart1.Repaint;  { <-- repaint chart to see changes }
  79. end;
  80.  
  81. procedure TAxisLabelsForm.Chart1GetNextAxisLabel(Sender: TChartAxis;
  82.   LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  83.  
  84. var year,month,day:Word;
  85. begin
  86.   if not DefaultLabels then
  87.   Begin
  88.     if Sender=Chart1.BottomAxis then
  89.     Begin
  90.       { ***************************** }
  91.       { WARNING:
  92.  
  93.           Setting this axis increment:
  94.  
  95.           Chart1.BottomAxis.Increment := DateTimeStep[ dtOneMonth ];
  96.  
  97.           and...
  98.  
  99.           Chart1.BottomAxis.ExactDateTime := True ;
  100.  
  101.           Eliminates the need for the following code.
  102.       }
  103.       { ***************************** }
  104.  
  105.      { LabelValue has the "candidate" value where the Axis label will be painted. }
  106.       DecodeDate(LabelValue,year,month,day);
  107.       { we force that value to be the first day in month }
  108.       Day:=1;
  109.       Month:=Month+1;
  110.       if Month>12 then
  111.       Begin
  112.         Month:=1;
  113.         Year:=Year+1;
  114.       end;
  115.       { Then we set the preferred Label value }
  116.       LabelValue:=EncodeDate(year,month,day);
  117.  
  118.     end
  119.     else
  120.     if Sender=Chart1.LeftAxis then
  121.     Begin
  122.       { In this example, we want the Vertical Left Axis to show
  123.         labels only for positive values, starting at zero and
  124.         with 250 label increment.
  125.       }
  126.       if LabelValue>=250 then LabelValue:=LabelValue+250
  127.                          else LabelValue:=250;
  128.     End;
  129.     { we want more labels !! }
  130.     Stop:=False;
  131.   end;
  132. end;
  133.  
  134.  
  135. end.
  136.