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=('一月','二月','三月','四月','五月','六月','七月','八月'
    ,'九月','十月','十一月', '十二月');
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:='居民用气';
  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:='工业用气';
  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:='居民下半年用气量';
  PieChart.Title.Font.Name:='宋体';
  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.
