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

  1. unit USurlab;
  2. {$P-}  { <--- VERY IMPORTANT FOR Delphi 1.0 }
  3.  
  4.  
  5. { This example draws custom Labels for the Bottom Axis of
  6.   a Surface Chart.
  7.   It also draws custom text as Surface Z legends.
  8. }
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, TeEngine, TeeSurfa, ExtCtrls, TeeProcs, Chart, StdCtrls,
  14.   Buttons, TeeComma;
  15.  
  16. type
  17.   TSurfaceLabelsForm = class(TForm)
  18.     Chart1: TChart;
  19.     Series1: TSurfaceSeries;
  20.     TeeCommander1: TTeeCommander;
  21.     Panel1: TPanel;
  22.     CheckBox1: TCheckBox;
  23.     Button1: TButton;
  24.     BitBtn1: TBitBtn;
  25.     procedure FormCreate(Sender: TObject);
  26.     procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  27.       ValueIndex: Longint; var LabelText: String);
  28.     procedure BitBtn1Click(Sender: TObject);
  29.     procedure CheckBox1Click(Sender: TObject);
  30.     procedure Button1Click(Sender: TObject);
  31.   private
  32.     { Private declarations }
  33.   public
  34.     { Public declarations }
  35.   end;
  36.  
  37. var
  38.   SurfaceLabelsForm: TSurfaceLabelsForm;
  39.  
  40. implementation
  41.  
  42. {$R *.DFM}
  43. Uses EditChar,EditPro;
  44.  
  45. { Arrange some properties for this demo... }
  46. procedure TSurfaceLabelsForm.FormCreate(Sender: TObject);
  47. begin
  48.   Series1.FillSampleValues(0);   { <-- random values for surface }
  49.  
  50.   { this forces GetAxisLabel to call for each "ValueIndex" in the Series.. }
  51.   Series1.XLabel[0]:='dummy';
  52.   Chart1.BottomAxis.LabelStyle:=talText;
  53.  
  54.   { extra space to draw labels... }
  55.   Chart1.MarginRight:=10;
  56. end;
  57.  
  58. { This event supplies the Labels for the X Axis  (Bottom)  }
  59. procedure TSurfaceLabelsForm.Chart1GetAxisLabel(Sender: TChartAxis;
  60.   Series: TChartSeries; ValueIndex: Longint; var LabelText: String);
  61. Var X,Z:Integer;
  62. begin
  63.   if ValueIndex>=0 then
  64.   if Sender=Chart1.BottomAxis then
  65.   begin
  66.     { calculate the X and Z for the ValueIndex }
  67.     X:=ValueIndex div Series1.NumZValues;
  68.     Z:=ValueIndex mod Series1.NumZValues;
  69.  
  70.     { Z=0 means we are at the front row of the surface,
  71.       so we can draw a X label:
  72.     }
  73.     if Z=0 then LabelText:=Chr(Ord('a')+X)    { <-- example }
  74.            else LabelText:='';
  75.   end
  76.   else
  77.   if Sender.IsDepthAxis then
  78.      LabelText:='='+FloatToStr(Series1.ZValues[ValueIndex]);
  79. end;
  80.  
  81. procedure TSurfaceLabelsForm.BitBtn1Click(Sender: TObject);
  82. begin
  83.   Close;
  84. end;
  85.  
  86. procedure TSurfaceLabelsForm.CheckBox1Click(Sender: TObject);
  87. begin
  88.   if CheckBox1.Checked then Chart1.DepthAxis.LabelStyle:=talText
  89.                        else Chart1.DepthAxis.LabelStyle:=talValue;
  90. end;
  91.  
  92. procedure TSurfaceLabelsForm.Button1Click(Sender: TObject);
  93. begin
  94.   EditChart(Self,Chart1);
  95. end;
  96.  
  97. end.
  98.