unit OleChart;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  BaseForm, AnyPrint, AnyGrids, ComCtrls, Buttons, ExtCtrls,AnyChart;

type
  TfrmOleChart = class(TfrmBase)
    Timer1: TTimer;
    Timer2: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    PieChart:TAnyChart;
    LineChart:TAnyChart;
    FastLine1:TAnySeries;
    FastLine2:TAnySeries;
  public
    { Public declarations }
  end;

var
  frmOleChart: TfrmOleChart;

implementation

{$R *.DFM}
const
  Months:array[0..11] of string=('Jun','Feb','Mar','Apr','May','Jun','Jul','Aug'
    ,'Sep','Oct','Nov', 'Dec');
procedure TfrmOleChart.Timer1Timer(Sender: TObject);
begin
  PieChart.Series(0).Rotate(5);
end;

procedure TfrmOleChart.Timer2Timer(Sender: TObject);
var
  tmpX:Double;
begin
  With FastLine1 do
  begin
    tmpX:=XValues.Value(1)-XValues.Value(0);
    Delete(0);
    AddXY(XValues.Last+tmpX,Random(100),'',clDefault);
  end;
  With FastLine2 do
  begin
    tmpX:=XValues.Value(1)-XValues.Value(0);
    Delete(0);
    AddXY(XValues.Last+tmpX,Random(100),'',clDefault);
  end;
end;

procedure TfrmOleChart.FormCreate(Sender: TObject);
var
  AChart:TAnyChart;
  S:TAnySeries;
  i:integer;
begin
  inherited;
  AChart:=AnyGrid.InsertChart('',6,0,True);
  AChart.Width:=Anygrid.InnerWidth;
  AChart.Height:=200;
  AChart.BorderVisible:=False;
  S:=AChart.AddSeries(stLine);
  S.Title:='Civilian';
  for i:=1 to 12 do
  begin
    S.AddXY(i,AnyGrid.Cells(2,i).AsFloat,Months[i-1],clDefault);
  end;
  S:=AChart.AddSeries(stLine);
  S.Title:='Industry';
  for i:=1 to 12 do
  begin
    S.AddXY(i,AnyGrid.Cells(3,i).AsFloat,Months[i-1],clDefault);
  end;
  //----------------------------------------------------------------------------
  PieChart:=AnyGrid.InsertChartByPos('',AChart.Left,AChart.Top+AChart.Height+50,True);
  PieChart.BorderVisible:=False;
  PieChart.Width:=Anygrid.InnerWidth;
  PieChart.Height:=200;
  PieChart.Title.Text:='Consumption of gas';
  PieChart.Title.Font.Size:=11;
  PieChart.Chart3DPercent:=30;
  S:=PieChart.AddSeries(stPie);
  PieChart.AxisVisible:=False;
  for i:=7 to 12 do
  begin
    S.AddXY(i,AnyGrid.Cells(2,i).AsFloat,Months[i-1],clDefault);
  end;
  //----------------------------------------------------------------------------
  LineChart:=AnyGrid.InsertChartByPos('',PieChart.Left+(AnyGrid.InnerWidth-141) div 2,
    PieChart.Top+PieChart.Height+50,True);
  LineChart.BorderVisible:=False;
  LineChart.Width:=141;
  LineChart.Height:=73;
  LineChart.AxisVisible:=False;
  LineChart.LegendVisible:=False;
  LineChart.View3D:=False;
  FastLine1:=LineChart.AddSeries(stFastLine);
  FastLine1.FillSampleValues(20);
  FastLine2:=LineChart.AddSeries(stFastLine);
  FastLine2.FillSampleValues(20);
  //----------------------------------------------------------------------------
  Timer1.Enabled:=True;
  Timer2.Enabled:=True;
end;

end.
