unit UPlots;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ToolWin, ImgList, ActnList, Series, TeEngine, ExtCtrls,
  TeeProcs, Chart, Math, GanttCh, BubbleCh, ArrowCha, TeeShape, StdCtrls;

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    Series2: TBarSeries;
    Series3: TBarSeries;
    ActionList1: TActionList;
    ALine: TAction;
    AFast: TAction;
    APoint: TAction;
    AArea: TAction;
    ABar: TAction;
    AHorBar: TAction;
    AGant: TAction;
    AArrows: TAction;
    ABubble: TAction;
    AShape: TAction;
    APie: TAction;
    A3D: TAction;
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton6: TToolButton;
    ToolButton12: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    Series4: THorizBarSeries;
    Series5: THorizBarSeries;
    Series6: TAreaSeries;
    Series7: TPointSeries;
    Series8: TPointSeries;
    Series10: TGanttSeries;
    Series11: TBubbleSeries;
    Series12: TArrowSeries;
    Series13: TChartShape;
    Series14: TChartShape;
    Series15: TFastLineSeries;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Series9: TPieSeries;
    AView: TAction;
    ToolButton5: TToolButton;
    ToolButton15: TToolButton;
    ToolButton16: TToolButton;
    ToolButton17: TToolButton;
    ToolButton18: TToolButton;
    ABCopy: TAction;
    AECopy: TAction;
    AWCopy: TAction;
    Series16: TFastLineSeries;
    Series17: TFastLineSeries;
    procedure A3DExecute(Sender: TObject);
    procedure ALineExecute(Sender: TObject);
    procedure ABarExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure AAreaExecute(Sender: TObject);
    procedure APointExecute(Sender: TObject);
    procedure APieExecute(Sender: TObject);
    procedure AGantExecute(Sender: TObject);
    procedure ABubbleExecute(Sender: TObject);
    procedure AArrowsExecute(Sender: TObject);
    procedure AShapeExecute(Sender: TObject);
    procedure AFastExecute(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure AViewExecute(Sender: TObject);
    procedure ABCopyExecute(Sender: TObject);
    procedure AECopyExecute(Sender: TObject);
    procedure AWCopyExecute(Sender: TObject);
  private
    { Private declarations }
   procedure ClearSeries;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses UView;

{$R *.DFM}

procedure TForm1.ClearSeries;
var i: integer;
begin
  Chart1.Visible := true;
  ComboBox1.Enabled := false;
  ComboBox2.Enabled := false;
  for i:= 0 to Chart1.SeriesCount - 1 do
   Chart1.Series[i].Active := false;
  Chart1.Title.Text.Clear;
  Chart1.View3dOptions.Orthogonal := FView.CheckBox1.Checked;
end;

procedure TForm1.A3DExecute(Sender: TObject);
begin
 Chart1.View3D := not Chart1.View3D;
 A3D.Checked := not A3D.Checked;
 AView.Enabled := A3D.Checked;
end;

procedure TForm1.AFastExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Legend.Visible := false;
  Chart1.AxisVisible := true;
  Chart1.Title.Text.Text := 'Колебания';
  Series15.Active := true;
end;

procedure TForm1.ABarExecute(Sender: TObject);
begin
  ClearSeries;
  ComboBox1.Enabled := true;
  ComboBox2.Enabled := true;
  Chart1.Title.Text.Add('Производство');
  Chart1.Title.Text.Add('(по месяцам)');
  Chart1.AxisVisible := true;
  if(Sender = ABar)
  then begin
   Series2.Active := true;
   Series3.Active := true;
  end
  else begin
   Series4.Active := true;
   Series5.Active := true;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
    X, Y, X0, Y0: real;
    xs1, xs2, ss1, rs1: double;
begin
 ComboBox1.ItemIndex := 0;
 ComboBox2.ItemIndex := 0;
 Chart1.View3dOptions.Orthogonal := true;
 for i := 0 to 501 do
  Series15.AddXY(0.2*i,sin(0.2*i)+sin(0.18*i),'',clRed);

 for i := 0 to 500 do
  Series1.AddXY(Pi*0.005*i,sin(Pi*0.005*i),'',clRed);

  Series2.Add(155,'Цех 1',GetDefaultColor(1));
  Series2.Add(251,'Цех 2',GetDefaultColor(2));
  Series2.Add(203,'Цех 3',GetDefaultColor(3));
  Series2.Add(404,'Цех 4',GetDefaultColor(4));

  Series3.Add(140,'Цех 1',GetDefaultColor(1));
  Series3.Add(20,'Цех 2',GetDefaultColor(2));
  Series3.Add(253,'Цех 3',GetDefaultColor(3));
  Series3.Add(200,'Цех 4',GetDefaultColor(4));

  Series4.AssignValues(Series2);
  Series5.AssignValues(Series3);

  Series9.AddPie(140,'Цех 1',clRed);
  Series9.AddPie(20,'Цех 2',clYellow);
  Series9.AddPie(253,'Цех 3',clBlue);
  Series9.AddPie(200,'Цех 4',clGreen);

  Series6.AddXY(EncodeDate(1994,2,1),1000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,3,1),2000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,4,1),4000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,5,1),8000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,6,1),16000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,7,1),32000000,'',clRed);
  Series6.AddXY(EncodeDate(1994,7,5),100000,'',clBlack);

  for i:=1 to 100 do begin
   X := RandG(10,0.5);
   Series7.AddXY(X,RandG(10+X,0.5),'',clRed);
   X := RandG(10,0.5);
   Series8.AddXY(X,RandG(30-X,0.5),'',clWhite);
  end;

  xs1 := 0;
  xs2 := 0;
  ss1 := 0;
  rs1 := 0;
  for i:= 0 to Series7.Count - 1 do begin
   xs1 := xs1 + Series7.XValue[i];
   xs2 := xs2 + Series7.YValue[i];
  end;
  xs1 := xs1 / Series7.Count;
  xs2 := xs2 / Series7.Count;
  for i:= 0 to Series7.Count - 1 do begin
   ss1 := ss1 + Sqr(Series7.XValue[i]-xs1);
   rs1 := rs1 + (Series7.XValue[i]-xs1)*(Series7.YValue[i]-xs2);
  end;
  ss1 := Sqrt(ss1 / (Series7.Count-1));
  rs1 := rs1 / (Series7.Count-1)/Sqr(ss1);
  Series16.AddXY(Series7.XValues.MinValue, xs2 + rs1*(Series7.XValues.MinValue - xs1));
  Series16.AddXY(Series7.XValues.MaxValue, xs2 + rs1*(Series7.XValues.MaxValue - xs1));

  xs1 := 0;
  xs2 := 0;
  ss1 := 0;
  rs1 := 0;
  for i:= 0 to Series8.Count - 1 do begin
   xs1 := xs1 + Series8.XValue[i];
   xs2 := xs2 + Series8.YValue[i];
  end;
  xs1 := xs1 / Series8.Count;
  xs2 := xs2 / Series8.Count;
  for i:= 0 to Series8.Count - 1 do begin
   ss1 := ss1 + Sqr(Series8.XValue[i]-xs1);
   rs1 := rs1 + (Series8.XValue[i]-xs1)*(Series8.YValue[i]-xs2);
  end;
  ss1 := Sqrt(ss1 / (Series8.Count-1));
  rs1 := rs1 / (Series8.Count-1)/Sqr(ss1);
  Series17.AddXY(Series8.XValues.MinValue, xs2 + rs1*(Series8.XValues.MinValue - xs1));
  Series17.AddXY(Series8.XValues.MaxValue, xs2 + rs1*(Series8.XValues.MaxValue - xs1));

  Series10.AddGantt(EncodeDate(2001,1,1),
                EncodeDate(2001,1,31), 0,
                'Программирование' );
  Series10.AddGantt(EncodeDate(2001,2,5),
                EncodeDate(2001,2,28), 0,
                'Программирование' );
  Series10.AddGantt(EncodeDate(2001,3,15),
                EncodeDate(2001,4,2), 0,
                'Программирование' );
  Series10.AddGantt(EncodeDate(2001,2,1),
                EncodeDate(2001,3,25), 1,
                'Отладка' );
  Series10.AddGantt(EncodeDate(2001,3,15),
                EncodeDate(2001,4,10), 2,
                'Тестирование' );
  Series10.AddGantt(EncodeDate(2001,4,11),
                EncodeDate(2001,4,30), 3,
                'Сдача заказчику');
  Series10.NextTask[4]:= 5 ;

  Series11.XValues.Order := loNone;
  Series11.AddBubble(1,40,40,'Цех 1', GetDefaultColor(1));
  Series11.AddBubble(1.5,10,10,'Цех 2', GetDefaultColor(2));
  Series11.AddBubble(2,60,20,'Цех 3', GetDefaultColor(3));
  Series11.AddBubble(2.2,30,25,'Цех 4', GetDefaultColor(4));
  Series11.AddBubble(0,0,0,' ', GetDefaultColor(1));
  Series11.AddBubble(3,0,0,' ', GetDefaultColor(2));

  X0 := 0;
  Y0 := 0;
  for i:= 1 to 200 do begin
   X := X0 + RandG(0,10);
   Y := Y0 + RandG(0,10);
   Series12.AddArrow(X0, Y0, X, Y, '', clBlack);
   X0 := X;
   Y0 := Y;
  end;

end;

procedure TForm1.AAreaExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Доходы');
  Chart1.Title.Text.Add('Лени Голубкова');
  Chart1.AxisVisible := true;
  Series6.Active := true;
end;

procedure TForm1.APointExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Эксперимент');
  Chart1.AxisVisible := true;
  Series7.Active := true;
  Series8.Active := true;
  Series16.Active := true;
  Series17.Active := true;
end;

procedure TForm1.APieExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Производство');
  Chart1.Title.Text.Add('за май 2002');
  Series9.Active := true;
end;

procedure TForm1.AGantExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.AxisVisible := true;
  Chart1.Title.Text.Add('Разработка программы');
  Series10.Active := true;
end;

procedure TForm1.ABubbleExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Полезная площадь цехов');
  Chart1.AxisVisible := false;
  Series11.Active := true;
end;

procedure TForm1.AArrowsExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Броуновское движение');
  Chart1.AxisVisible := false;
  Series12.Active := true;
end;

procedure TForm1.AShapeExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.Title.Text.Add('Формы');
  Chart1.AxisVisible := false;

  Series13.X0 := 20;
  Series13.Y0 := 40;
  Series13.X1 := 80;
  Series13.Y1 := 70;
  Series13.Text.Clear;
  Series13.Text.Add('Эта форма овала');
  Series13.Text.Add('просто великолепна !!!');
  Series13.Active := true;
  Series14.Y0 := 100;
  Series14.Y1 := 85;
  Series14.Text.Clear;
  Series14.Text.Add('Это прямоугольная форма');
  Series14.Active := true;
end;

procedure TForm1.ALineExecute(Sender: TObject);
begin
  ClearSeries;
  Chart1.AxisVisible := true;
  Chart1.Title.Text.Text := 'Синус';
  Series1.Active := true;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
 Case ComboBox1.ItemIndex of
  0: begin
      Series2.BarStyle := bsRectangle;
      Series3.BarStyle := bsRectangle;
      Series4.BarStyle := bsRectangle;
      Series5.BarStyle := bsRectangle;
     end;
  1: begin
      Series2.BarStyle := bsPyramid;
      Series3.BarStyle := bsPyramid;
      Series4.BarStyle := bsPyramid;
      Series5.BarStyle := bsPyramid;
     end;
  2: begin
      Series2.BarStyle := bsInvPyramid;
      Series3.BarStyle := bsInvPyramid;
      Series4.BarStyle := bsInvPyramid;
      Series5.BarStyle := bsInvPyramid;
     end;
  3: begin
      Series2.BarStyle := bsCilinder;
      Series3.BarStyle := bsCilinder;
      Series4.BarStyle := bsCilinder;
      Series5.BarStyle := bsCilinder;
     end;
  4: begin
      Series2.BarStyle := bsEllipse;
      Series3.BarStyle := bsEllipse;
      Series4.BarStyle := bsEllipse;
      Series5.BarStyle := bsEllipse;
     end;
  5: begin
      Series2.BarStyle := bsArrow;
      Series3.BarStyle := bsArrow;
      Series4.BarStyle := bsArrow;
      Series5.BarStyle := bsArrow;
     end;
  6: begin
{      Series2.BarStyle := bsCone;
      Series3.BarStyle := bsCone;
      Series4.BarStyle := bsCone;
      Series5.BarStyle := bsCone;}
     end;
 end;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
begin
 Case ComboBox2.ItemIndex of
  0: begin
      Series2.MultiBar := mbNone;
      Series3.MultiBar := mbNone;
      Series4.MultiBar := mbNone;
      Series5.MultiBar := mbNone;
     end;
  1: begin
      Series2.MultiBar := mbSide;
      Series3.MultiBar := mbSide;
      Series4.MultiBar := mbSide;
      Series5.MultiBar := mbSide;
     end;
  2: begin
      Series2.MultiBar := mbStacked;
      Series3.MultiBar := mbStacked;
      Series4.MultiBar := mbStacked;
      Series5.MultiBar := mbStacked;
     end;
  3: begin
      Series2.MultiBar := mbStacked100;
      Series3.MultiBar := mbStacked100;
      Series4.MultiBar := mbStacked100;
      Series5.MultiBar := mbStacked100;
     end;
 end;
end;

procedure TForm1.AViewExecute(Sender: TObject);
begin
 FView.Show;
end;

procedure TForm1.ABCopyExecute(Sender: TObject);
begin
 Chart1.CopyToClipboardBitmap;
end;

procedure TForm1.AECopyExecute(Sender: TObject);
begin
 Chart1.CopyToClipboardMetafile(true);
end;

procedure TForm1.AWCopyExecute(Sender: TObject);
begin
 Chart1.CopyToClipboardMetafile(false);
end;

end.
