home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue51 / Observer / FObserver_PieGraph.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-10-08  |  2.0 KB  |  83 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   (c) TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: October 1999
  10.  
  11.   Notes: View the subject (portfolio) as a pie graph
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit FObserver_PieGraph;
  15.  
  16. interface
  17.  
  18. uses
  19.   Windows, Messages, SysUtils, Classes, Graphics, Controls,
  20.   Forms, Dialogs, StdCtrls, TeEngine, Series, ExtCtrls,
  21.   TeeProcs, Chart, FObserver_Abstract ;
  22.  
  23. type
  24.  
  25.   //--------------------------------------------------------
  26.   TFormObserverPieGraph = class(TFormObserverAbstract)
  27.     Chart1: TChart;
  28.     Series1: TPieSeries;
  29.     procedure FormCreate(Sender: TObject);
  30.   private
  31.     // Get a unique colour to display in the graph
  32.     function GetColour(const pI: integer): TColor;
  33.   public
  34.     procedure DataToObserver ; override ;
  35.   end;
  36.  
  37. implementation
  38. uses
  39.   Subject_Portfolio ;
  40.  
  41. {$R *.DFM}
  42.  
  43. { TFormViewPieGraph }
  44.  
  45. procedure TFormObserverPieGraph.DataToObserver ;
  46. var
  47.   i           : integer ;
  48.   lStockTrans : TStockTrans ;
  49. begin
  50.   chart1.series[0].clear ;
  51.   with (Subject as TPortfolio) do begin
  52.     for i := 0 to Stocks.Count - 1 do begin
  53.       lStockTrans := Stocks.Items[ i ] ;
  54.       chart1.series[0].add( lStockTrans.Value, lStockTrans.StockCode, GetColour( i ))  ;
  55.     end ;
  56.   end ;
  57. end;
  58.  
  59. procedure TFormObserverPieGraph.FormCreate(Sender: TObject);
  60. begin
  61.   inherited;
  62.   Subject := gPortfolio ;
  63. end;
  64.  
  65. // Get a unique colour to display in the graph
  66. //----------------------------------------------------------
  67. function TFormObserverPieGraph.GetColour(const pI:
  68.                                            integer): TColor;
  69. begin
  70.   case pI of
  71.     0 : result := clRed ;
  72.     1 : result := clBlue ;
  73.     2 : result := clGreen ;
  74.     3 : result := clYellow ;
  75.     4 : result := clAqua ;
  76.   else
  77.     result := clBlack ;
  78.   end ;
  79. end;
  80.  
  81. end.
  82.  
  83.