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

  1. {*********************************************}
  2. {  TeeChart Pro 4 example                     }
  3. {  Copyright (c) 1995-1998 by David Berneda   }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit UPareto;
  7.  
  8. interface
  9.  
  10. uses
  11.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12.   TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
  13.  
  14. type
  15.   TFormPareto = class(TForm)
  16.     Chart1: TChart;
  17.     Series1: TBarSeries;
  18.     Series2: TLineSeries;
  19.     CheckBox1: TCheckBox;
  20.     CheckBox2: TCheckBox;
  21.     CheckBox3: TCheckBox;
  22.     CheckBox4: TCheckBox;
  23.     CheckBoxPercent: TCheckBox;
  24.     CheckBox5: TCheckBox;
  25.     Button1: TButton;
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure CheckBox3Click(Sender: TObject);
  28.     procedure CheckBox2Click(Sender: TObject);
  29.     procedure CheckBox4Click(Sender: TObject);
  30.     procedure CheckBox1Click(Sender: TObject);
  31.     procedure CheckBoxPercentClick(Sender: TObject);
  32.     procedure CheckBox5Click(Sender: TObject);
  33.     procedure Button1Click(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     { Public declarations }
  38.     Procedure CalcPareto(Percent:Boolean);
  39.   end;
  40.  
  41. var
  42.   FormPareto: TFormPareto;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. Procedure TFormPareto.CalcPareto(Percent:Boolean);
  49. var tmp:Double;
  50.     t:Integer;
  51. begin
  52.   { First order the Bar values }
  53.   Series1.YValues.Sort;
  54.   { Then reposition each bar in the right X }
  55.   Series1.XValues.FillSequence;
  56.  
  57.   { Calculate the line points }
  58.   Series2.Clear;
  59.   tmp:=0;
  60.   for t:=0 to Series1.Count-1 do
  61.   begin
  62.     tmp:=tmp+Series1.YValues[t];
  63.     if Percent then
  64.        Series2.Add( 100.0*tmp/Series1.YValues.TotalABS, '', clTeeColor)
  65.     else
  66.        Series2.Add( tmp, '', clTeeColor)
  67.   end;
  68. end;
  69.  
  70. procedure TFormPareto.FormCreate(Sender: TObject);
  71. var t:Integer;
  72. begin
  73.   { Useful properties }
  74.   Series2.VertAxis:=aRightAxis;
  75.   Chart1.RightAxis.SetMinMax(0,100);
  76.   Series1.Marks.Visible:=False;
  77.  
  78.   { Sample random values }
  79.   Series1.Clear;
  80.   for t:=0 to 7 do Series1.Add( t*100+Random(100),'', clTeeColor);
  81.  
  82.   { Set the Left axis }
  83.   Chart1.LeftAxis.SetMinMax(0, Series1.YValues.Total );
  84.  
  85.   { Calc the pareto line }
  86.   CalcPareto(CheckBoxPercent.Checked);
  87. end;
  88.  
  89. procedure TFormPareto.CheckBox3Click(Sender: TObject);
  90. begin
  91.  Series1.ColorEachPoint:=CheckBox3.Checked;
  92.  Series2.ColorEachPoint:=CheckBox3.Checked;
  93. end;
  94.  
  95. procedure TFormPareto.CheckBox2Click(Sender: TObject);
  96. begin
  97.   if CheckBox2.Checked then Series2.ZOrder:=0
  98.                        else Series2.ZOrder:=1;
  99. end;
  100.  
  101. procedure TFormPareto.CheckBox4Click(Sender: TObject);
  102. begin
  103.   if CheckBox4.Checked then
  104.      Series1.YValues.Order:=loDescending
  105.   else
  106.      Series1.YValues.Order:=loAscending;
  107.   CalcPareto(CheckBoxPercent.Checked);
  108. end;
  109.  
  110. procedure TFormPareto.CheckBox1Click(Sender: TObject);
  111. begin
  112.   Chart1.View3D:=CheckBox1.Checked;
  113. end;
  114.  
  115. procedure TFormPareto.CheckBoxPercentClick(Sender: TObject);
  116. begin
  117.   CalcPareto(CheckBoxPercent.Checked);
  118.   if CheckBoxPercent.Checked then
  119.      Chart1.RightAxis.SetMinMax(0,100)
  120.   else
  121.      Chart1.RightAxis.SetMinMax(0,Series2.YValues.MaxValue);
  122.  
  123.   Series2.Pointer.Style:=psCircle;
  124.  
  125. end;
  126.  
  127. procedure TFormPareto.CheckBox5Click(Sender: TObject);
  128. begin
  129.   if CheckBox5.Checked then
  130.   begin
  131.     Series1.VertAxis:=aRightAxis;
  132.     Series2.VertAxis:=aLeftAxis;
  133.   end
  134.   else
  135.   begin
  136.     Series1.VertAxis:=aLeftAxis;
  137.     Series2.VertAxis:=aRightAxis;
  138.   end;
  139.   Series1.GetVertAxis.SetMinMax(0, Series1.YValues.Total);
  140.   Series2.GetVertAxis.SetMinMax(0, 100);
  141. end;
  142.  
  143. procedure TFormPareto.Button1Click(Sender: TObject);
  144. begin
  145.   Close
  146. end;
  147.  
  148. end.
  149.