home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / TEECHART / UYLEGEND.PAS < prev   
Pascal/Delphi Source File  |  1998-06-16  |  3KB  |  89 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Custom Legend Size and Position Demo        }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Uylegend;
  8.  
  9. interface
  10. { This form shows a customized Legend.
  11.   The Chart.OnGetLegendRect and Chart.OnGetLegendPos events are used to
  12.   change the default legend size and the default legend text positions.
  13. }
  14. uses
  15.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  16.   Forms, Dialogs, ExtCtrls, Chart, Series, StdCtrls, Teengine, Buttons,
  17.   TeeProcs;
  18.  
  19. type
  20.   TLegendXYForm = class(TForm)
  21.     Chart1: TChart;
  22.     PieSeries1: TPieSeries;
  23.     Panel1: TPanel;
  24.     RadioGroup1: TRadioGroup;
  25.     BitBtn3: TBitBtn;
  26.     Memo1: TMemo;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
  29.     procedure Chart1GetLegendPos(Sender: TCustomChart; Index: Longint;
  30.       var X, Y, XColor: Longint);
  31.     procedure RadioGroup1Click(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.     DefaultLegend:Boolean;
  37.   end;
  38.  
  39. var
  40.   LegendXYForm: TLegendXYForm;
  41.  
  42. implementation
  43.  
  44. {$R *.DFM}
  45.  
  46. procedure TLegendXYForm.FormCreate(Sender: TObject);
  47. begin
  48.   DefaultLegend:=False;              { <-- only used in this example }
  49.   PieSeries1.FillSampleValues(10);   { <-- some random pie sectors }
  50. end;
  51.  
  52. procedure TLegendXYForm.Chart1GetLegendRect(Sender: TCustomChart;
  53.   var Rect: TRect);
  54. begin
  55.   if not DefaultLegend then  { <-- if we want to customize legend... }
  56.   Begin
  57.     { This changes the Legend Rectangle dimensions }
  58.     Rect.Bottom:=Rect.Top+PieSeries1.Count*15;  { <-- Calc Legend Height }
  59.     Rect.Left:=Rect.Left-120;                   { <-- Bigger Legend Width }
  60.   end;
  61. end;
  62.  
  63. procedure TLegendXYForm.Chart1GetLegendPos(Sender: TCustomChart; Index: Longint;
  64.   var X, Y, XColor: Longint);
  65. begin
  66.   if not DefaultLegend then
  67.   Begin
  68.     { Calculate the X Y coordinates for each Legend Text }
  69.     x:=Chart1.Legend.RectLegend.Left;
  70.     x:=x + (Index div (PieSeries1.Count div 2))*100;
  71.  
  72.     y:=Chart1.Legend.RectLegend.Top;
  73.     y:=y +   (Index mod (PieSeries1.Count div 2))*30;
  74.  
  75.     if (Index mod 2)=1 then X:=X+20;
  76.     x:=x+20;
  77.     XColor:=X-15;
  78.   end;
  79. end;
  80.  
  81. procedure TLegendXYForm.RadioGroup1Click(Sender: TObject);
  82. begin
  83.   { Get the RadioGroup selection and force the chart to repaint }
  84.   DefaultLegend:=RadioGroup1.ItemIndex=0;
  85.   Chart1.Repaint;
  86. end;
  87.  
  88. end.
  89.