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

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Bubble Series Type Demo                     }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Bubble;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, Chart, Series, ExtCtrls, StdCtrls, BubbleCh,
  14.   Teengine, Buttons, TeeProcs;
  15.  
  16. type
  17.   TBubbleForm = class(TForm)
  18.     Chart1: TChart;
  19.     Panel1: TPanel;
  20.     CheckBox1: TCheckBox;
  21.     Timer1: TTimer;
  22.     CheckBox2: TCheckBox;
  23.     ComboBox1: TComboBox;
  24.     Label1: TLabel;
  25.     BitBtn3: TBitBtn;
  26.     CheckBox3: TCheckBox;
  27.     BubbleSeries1: TBubbleSeries;
  28.     ZoomInButton: TSpeedButton;
  29.     ZoomOutButton: TSpeedButton;
  30.     Memo1: TMemo;
  31.     procedure FormCreate(Sender: TObject);
  32.     procedure CheckBox1Click(Sender: TObject);
  33.     procedure Timer1Timer(Sender: TObject);
  34.     procedure CheckBox2Click(Sender: TObject);
  35.     procedure ComboBox1Change(Sender: TObject);
  36.     procedure CheckBox3Click(Sender: TObject);
  37.     function BubbleSeries1GetPointerStyle(Sender: TChartSeries;
  38.       ValueIndex: Longint): TSeriesPointerStyle;
  39.     procedure ZoomInButtonClick(Sender: TObject);
  40.     procedure ZoomOutButtonClick(Sender: TObject);
  41.   private
  42.     { Private declarations }
  43.   public
  44.     { Public declarations }
  45.   end;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50.  
  51. procedure TBubbleForm.FormCreate(Sender: TObject);
  52. var t:Longint;
  53. begin
  54.   ComboBox1.ItemIndex:=Ord(psCircle); { <-- Circled Bubbles by default }
  55.   BubbleSeries1.Clear;
  56.   for t:=1 to 100 do
  57.       BubbleSeries1.AddBubble( Date+t,
  58.                                Random(ChartSamplesMax),         { <-- y value }
  59.                                ChartSamplesMax/(20+Random(25)), { <-- radius value }
  60.                                '',                              { <-- label string }
  61.                                GetDefaultColor(t));             { <-- color }
  62. end;
  63.  
  64. procedure TBubbleForm.CheckBox1Click(Sender: TObject);
  65. begin
  66.   Timer1.Enabled:=CheckBox1.Checked; { <-- on / off animation }
  67. end;
  68.  
  69. procedure TBubbleForm.Timer1Timer(Sender: TObject);
  70. Var tmpColor:TColor;
  71. Begin
  72.   Timer1.Enabled:=False;  { <-- stop the timer (this is optional) }
  73.   With BubbleSeries1 do
  74.   Begin
  75.     tmpColor:=ValueColor[0];
  76.     Delete(0); { <-- remove the first point }
  77.     { Add a new random bubble }
  78.     AddBubble( XValues.Last+1,                  { <-- x value }
  79.                Random(ChartSamplesMax),         { <-- y value }
  80.                ChartSamplesMax/(20+Random(25)), { <-- radius value }
  81.                '',                              { <-- label string }
  82.                tmpColor);                       { <-- color }
  83.   end;
  84.   if Random(100)<8 then
  85.   begin
  86.     if ComboBox1.ItemIndex<ComboBox1.Items.Count-1 then
  87.        ComboBox1.ItemIndex:=ComboBox1.ItemIndex+1
  88.     else
  89.        ComboBox1.ItemIndex:=0;
  90.     ComboBox1Change(Self);
  91.   end;
  92.   if (GetTickCount mod 1000)<=55 then
  93.   begin
  94.     with BubbleSeries1.GetHorizAxis.Title do
  95.      if Angle>=90 then Angle:=Angle-90 else Angle:=270;
  96.  
  97.     with BubbleSeries1.GetVertAxis.Title do
  98.      if Angle>=90 then Angle:=Angle-90 else Angle:=270;
  99.  
  100.     with BubbleSeries1.GetVertAxis do
  101.      if LabelsAngle>=90 then LabelsAngle:=LabelsAngle-90 else LabelsAngle:=270;
  102.  
  103.     with BubbleSeries1.GetHorizAxis do
  104.      if LabelsAngle>=90 then LabelsAngle:=LabelsAngle-90 else LabelsAngle:=270;
  105.   end;
  106.   Timer1.Enabled:=True;  { <-- restart the timer }
  107. end;
  108.  
  109. procedure TBubbleForm.CheckBox2Click(Sender: TObject);
  110. begin
  111.   BubbleSeries1.Marks.Visible:=CheckBox2.Checked; { switch on/off Marks }
  112. end;
  113.  
  114. procedure TBubbleForm.ComboBox1Change(Sender: TObject);
  115. begin { the demo combobox1 allows changing Bubble style }
  116.   BubbleSeries1.Pointer.Style:=TSeriesPointerStyle(ComboBox1.ItemIndex);
  117. end;
  118.  
  119. procedure TBubbleForm.CheckBox3Click(Sender: TObject);
  120. begin
  121.   Chart1.Repaint;
  122. end;
  123.  
  124. function TBubbleForm.BubbleSeries1GetPointerStyle(Sender: TChartSeries;
  125.   ValueIndex: Longint): TSeriesPointerStyle;
  126. begin
  127.   if CheckBox3.Checked then
  128.      result:=TSeriesPointerStyle(Random(Ord(High(TSeriesPointerStyle))))
  129.   else
  130.      result:=BubbleSeries1.Pointer.Style;
  131. end;
  132.  
  133. procedure TBubbleForm.ZoomInButtonClick(Sender: TObject);
  134. begin
  135.   Chart1.ZoomPercent(110);
  136. end;
  137.  
  138. procedure TBubbleForm.ZoomOutButtonClick(Sender: TObject);
  139. begin
  140.   Chart1.ZoomPercent(90);
  141. end;
  142.  
  143.  
  144.  
  145. end.
  146.