home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Pro 4 example }
- { Copyright (c) 1995-1998 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit uquali;
-
- interface
-
- uses
- Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, Series, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls,
- TeeComma;
-
- type
- TFormQuality = class(TForm)
- Chart1: TChart;
- Good: TLineSeries;
- Bad: TLineSeries;
- Upper: TFastLineSeries;
- Lower: TFastLineSeries;
- Memo1: TMemo;
- Button1: TButton;
- Label1: TLabel;
- Label2: TLabel;
- UpperEdit: TEdit;
- LowerEdit: TEdit;
- Button2: TButton;
- TeeCommander1: TTeeCommander;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure UpperEditChange(Sender: TObject);
- procedure LowerEditChange(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- UpperLim,
- LowerLim:Double;
- Procedure CalculateSPC(GoodSeries,BadSeries:TChartSeries);
- end;
-
- var
- FormQuality: TFormQuality;
-
- implementation
-
- {$R *.DFM}
- Uses EditChar;
-
- { Calculate the upper and lower limits }
- Procedure TFormQuality.CalculateSPC(GoodSeries,BadSeries:TChartSeries);
- Var Sum,SumN,
- tmp,Aux,LCP,LCN,NumTotal,
- Percent:Double;
- t,N:Longint;
- Begin
- UpperLim:=0;
- LowerLim:=0;
- Sum:=0;
- SumN:=0;
- N:=0;
- for t:=0 to GoodSeries.Count-1 do
- begin
- Percent:=(BadSeries.YValues[t]*GoodSeries.YValues[t]/100.0);
- NumTotal:=GoodSeries.YValues[t]+Percent;
- if NumTotal>0 then
- Begin
- Sum:=Sum+Percent/NumTotal;
- SumN:=SumN+NumTotal;
- inc(n);
- end;
- end;
- LCP:=Sum/n;
- LCN:=SumN/n;
- tmp:=(LCP*(1-LCP))/LCN;
- if tmp>0 then
- Begin
- Aux:=3*Sqrt(tmp); { <-- 3 by square root }
- UpperLim:=100.0*(LCP+Aux);
- LowerLim:=100.0*(LCP-Aux);
- end;
- End;
-
- procedure TFormQuality.FormCreate(Sender: TObject);
- var t:Integer;
- begin
- Good.Clear;
- for t:=0 to 19 do Good.Add(800+Random(200),'',clTeeColor);
-
- Bad.Clear;
- for t:=0 to 19 do Bad.Add(4+Random(4),'',clTeeColor);
-
- CalculateSPC(Good,Bad);
-
- UpperEdit.Text:=FloatToStr(UpperLim);
- LowerEdit.Text:=FloatToStr(LowerLim);
-
- Chart1.LeftAxis.SetMinMax(0,1100);
- Chart1.RightAxis.SetMinMax(0,10);
- end;
-
- procedure TFormQuality.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TFormQuality.UpperEditChange(Sender: TObject);
- var tmp:Double;
- begin
- try
- tmp:=StrToFloat(UpperEdit.Text);
- except
- on exception do exit;
- end;
- Upper.Clear;
- Upper.AddXY(0,tmp,'',clTeeColor);
- Upper.AddXY(19,tmp,'',clTeeColor);
- end;
-
- procedure TFormQuality.LowerEditChange(Sender: TObject);
- var tmp:Double;
- begin
- try
- tmp:=StrToFloat(LowerEdit.Text);
- except
- on exception do exit;
- end;
- Lower.Clear;
- Lower.AddXY(0,tmp,'',clTeeColor);
- Lower.AddXY(19,tmp,'',clTeeColor);
- end;
-
- procedure TFormQuality.Button2Click(Sender: TObject);
- begin
- ShowMessage( 'Calculating and charting the Upper and'+#13+
- 'Lower limits of an SPC Quality Control'+#13+
- 'series.'+#13+
- '--------------------------------------------'+#13+
- ''+#13+
- 'This example includes formulae to calculate'+#13+
- 'the SPC upper and lower limits.'+#13+
- ''+#13+
- 'The Chart displays 2 series, one with'+#13+
- 'the number of "good" parts and another with'+#13+
- 'the percent of "bad" parts.'+#13+
- ''+#13+
- 'With these two Series, the example calculates'+#13+
- 'two values: the upper and lower limits.'+#13+
- ''+#13+
- 'These limits are displayed using another two'+#13+
- 'series.'+#13+
- ''+#13+
- 'Disclaimer:'+#13+
- 'Correctness of calculation depends very much'+#13+
- 'on your particular country rules.');
- end;
-
- end.
-