unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, Grids, DBGrids, TeEngine, Series, TeeProcs, Chart,
  DBChart, ExtCtrls, DB, DBTables, StdCtrls, TeeFunci,TeeDBSumEdit,
  TeeDBEdit, TeeDBCrossTab;

type
  TForm1 = class(TForm)
    Table1: TTable;
    Panel1: TPanel;
    DBChart1: TDBChart;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    RadioGroup2: TRadioGroup;
    RadioGroup3: TRadioGroup;
    Series1: TBarSeries;
    DataSource1: TDataSource;
    procedure Button2Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure RadioGroup2Click(Sender: TObject);
    procedure RadioGroup3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DBChart1ClickSeries(Sender: TCustomChart;
      Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure FormActivate(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  nBlod:Integer;
implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:  Series1.YValues.ValueSource := '#Sum#Area';       //面积求和
1:  Series1.YValues.ValueSource := '#Sum#Population'; //人口求和
2:  Series1.YValues.ValueSource := '#Count#Area';     //面积计数
3:  Series1.YValues.ValueSource := '#High#Area';     //面积高值
4:  Series1.YValues.ValueSource := '#Low#Area';     //面积低值
5:  Series1.YValues.ValueSource := '#Average#Area';     //面积平均
6:  Series1.YValues.ValueSource := '#Average#Population';     //人口平均
end;

end;

procedure TForm1.RadioGroup2Click(Sender: TObject);
begin
//TChartListOrder =( loNone, loAscending, loDescending );
case RadioGroup2.ItemIndex of
0: Series1.SortByLabels(loNone);   //不排序
1: Series1.SortByLabels(loAscending);   //升序
2: Series1.SortByLabels(loDescending);   //降序
end;
end;



procedure TForm1.RadioGroup3Click(Sender: TObject);
begin  //按Y值排序
case RadioGroup3.ItemIndex of
0: Series1.YValues.Order := loNone;   //不排序
1: Series1.YValues.Order := loAscending;   //升序
2: Series1.YValues.Order := loDescending;   //降序
end;
DBChart1.RefreshData;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.DBChart1ClickSeries(Sender: TCustomChart;
  Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Table1.RecNo := ValueIndex+1;
Series.Marks.Item[nBlod].Font.Style := [];
Series.Marks.Item[nBlod].Font.Color := clBlack;
nBlod:=ValueIndex;
Series.Marks.Item[ValueIndex].Font.Style := [fsBold];
Series.Marks.Item[ValueIndex].Font.Color := clRed;
end;

procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
Series1.Marks.Item[nBlod].Font.Style :=  [];
Series1.Marks.Item[nBlod].Font.Color := clBlack;
nBlod := Table1.RecNo-1;
Series1.Marks.Item[nBlod].Font.Style :=  [fsBold];
Series1.Marks.Item[nBlod].Font.Color := clRed;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
nBlod:=0;
Series1.Marks.Item[nBlod].Font.Style := [fsBold];
Series1.Marks.Item[nBlod].Font.Color := clRed;
end;

procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
Series1.Marks.Item[nBlod].Font.Style :=  [];
Series1.Marks.Item[nBlod].Font.Color := clBlack;
nBlod := Table1.RecNo-1;
Series1.Marks.Item[nBlod].Font.Style :=  [fsBold];
Series1.Marks.Item[nBlod].Font.Color := clRed;
end;

end.

