unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, TeeSurfa, TeeMapSeries, ExtCtrls, TeeProcs, Chart,
  StdCtrls, Buttons, Grids, TeeChartGrid, TeeTools, TeeSelectorTool, Series,
  TeeLegendScrollBar, ComCtrls, TeeLighting, TeeComma, TeeEdit;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Chart1: TChart;
    Series1: TMapSeries;
    Button1: TButton;
    ChartTool1: TMarksTipTool;
    ChartTool2: TLegendScrollBar;
    ChartTool3: TCursorTool;
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    StatusBar1: TStatusBar;
    ChartTool4: TLightTool;
    CheckBox4: TCheckBox;
    TeeCommander1: TTeeCommander;
    CheckBox5: TCheckBox;
    ChartEditor1: TChartEditor;
    Button2: TButton;
    procedure AddShape(X, Y :array of integer; Color:TColor; Labels:String);

    procedure Series1Click(Sender: TChartSeries; ValueIndex: Integer;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure ChartTool1GetText(Sender: TMarksTipTool; var Text: String);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  AX: array[0..13] of integer =(1, 3, 4, 4, 5, 5, 6,  6,  4,  3,  2,  1,  2,  2);
  AY: array[0..13] of integer =(7, 5, 5, 7, 8, 9, 10, 11, 11, 12, 12, 11, 10, 8);
  BX: array[0..8]  of integer =(5, 7, 8, 8, 7, 6, 5, 4, 4);
  BY: array[0..8]  of integer =(4, 4, 5, 6, 7, 7, 8, 7, 5);
  CX: array[0..15]  of integer =(9, 10, 11, 11, 12, 9, 8, 7, 6, 6, 5, 5, 6, 7, 8, 8);
  CY: array[0..15]  of integer =(5, 6, 6, 7, 8, 11, 11, 12, 11, 10, 9, 8, 7, 7, 6, 5);
  DX: array[0..7]  of integer =(12, 14, 15, 14, 13, 12, 11, 11);
  DY: array[0..7]  of integer =(5, 5, 6, 7, 7, 8, 7, 6);
  EX: array[0..10]  of integer =(4,  6,  7,  7,  6,  6,  5,  4,  3,  3,  2);
  EY: array[0..10]  of integer =(11, 11, 12, 13, 14, 15, 16, 16, 15, 14, 13);
  FX: array[0..11]  of integer =(7,  8,  9,  11, 10, 8,  7,  6,  5,  5,  6,  6);
  FY: array[0..11]  of integer =(13, 14, 14, 16, 17, 17, 18, 18, 17, 16, 15, 14);
  GX: array[0..11]  of integer =(10, 12, 12, 14, 13, 11, 9,  8,  7,  7,  8,  9);
  GY: array[0..11]  of integer =(10, 12, 13, 15, 16, 16, 14, 14, 13, 12, 11, 11);
  HX: array[0..9]  of integer =(17, 19, 18, 18, 17, 15, 14, 13, 15, 16);
  HY: array[0..9]  of integer =(11, 13, 14, 16, 17, 15, 15, 14, 12, 12);
  IX: array[0..14]  of integer =(15, 16, 17, 16, 15, 14, 14, 13, 12, 11, 10, 11, 12, 13, 14);
  IY: array[0..14]  of integer =(6,  6,  7,  8,  8,  9,  10, 11, 12, 11, 10, 9,  8,  7,  7);
  JX: array[0..11]  of integer =(15, 16, 16, 17, 17, 16, 15, 13, 12, 12, 14, 14);
  JY: array[0..11]  of integer =(8,  8,  9,  10, 11, 12, 12, 14, 13, 12, 10, 9);
  KX: array[0..9]   of integer =(17, 19, 20, 20, 19, 17, 16, 16, 17, 16);
  KY: array[0..9]   of integer =(5,  5,  6,  8,  8,  10, 9,  8,  7,  6);
  LX: array[0..6]   of integer =(19, 20, 21, 21, 19, 17, 17);
  LY: array[0..6]   of integer =(8,  8,  9,  11, 13, 11, 10);
  Index:Integer=0;
implementation

{$R *.dfm}

procedure TForm1.AddShape(X, Y :array of integer; Color:TColor; Labels:String);
var
i,tmpIndex:integer;
begin
tmpIndex := Series1.Shapes.Count;
Series1.Shapes.Add;
for i:=0 to High(X) do
  Series1.Shapes.Polygon[tmpIndex].AddXY(X[i],Y[i]);
Series1.Shapes.Polygon[tmpIndex].Color := Color;
Series1.Shapes.Polygon[tmpIndex].Text  := Labels;
Series1.Shapes.Polygon[tmpIndex].Z     := Random;
end;



procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
mstr:string;
begin
mstr := '光标处值索引(GetCursorValueIndex):'+Inttostr(Sender.GetCursorValueIndex);
mstr := mstr+ ' 值索引(ValueIndex):'+Inttostr(ValueIndex);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
AddShape(AX,AY,RGB(250,245,128),'北京');
AddShape(BX,BY,RGB(250,245,132),'西安');
AddShape(CX,CY,RGB(250,245,136),'上海');
AddShape(DX,DY,RGB(250,245,140),'天津');
AddShape(EX,EY,RGB(250,245,144),'拉萨');
AddShape(FX,FY,RGB(250,245,148),'乌市');
AddShape(GX,GY,RGB(250,245,152),'南京');
AddShape(HX,HY,RGB(250,245,156),'昆明');
AddShape(IX,IY,RGB(250,245,160),'武汉');
AddShape(JX,JY,RGB(250,245,164),'厦门');
AddShape(KX,KY,RGB(250,245,168),'海口');
Chart1.Refresh;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
c:TColor;
mstr:string;
begin
c:= Series1.Shapes.Polygon[Index].Color;
Series1.Shapes.Polygon[Index].Color := RGB(255,0,64);
Chart1.Refresh;
Series1.Shapes.Polygon[Index].Color := c;
Chart1.Refresh;
StatusBar1.SimpleText := mstr;
end;

procedure TForm1.ChartTool1GetText(Sender: TMarksTipTool;
  var Text: String);
var
ID:integer;
mstr:string;
begin
mstr := '标签：'+Text;
ID := Series1.Shapes.ByName[Text].ID;
Index := ID;
mstr := mstr+'  索引(Series1.Shapes.ByName[Text].ID):'+ Inttostr(Series1.Shapes.ByName[Text].ID);
StatusBar1.SimpleText := mstr;
Chart1.Refresh;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
Series1.Marks.Visible := Checkbox1.Checked;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
Chart1.Legend.Visible := CheckBox2.Checked;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
ChartTool1.Active := CheckBox3.Checked;  //标签
ChartTool2.Active := CheckBox3.Checked;  //图例
ChartTool3.Active := CheckBox3.Checked;  //十字光标
ChartTool4.Active := CheckBox3.Checked;  //灯光
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin
ChartTool4.Active := CheckBox4.Checked;
end;

procedure TForm1.CheckBox5Click(Sender: TObject);
begin
ChartTool3.Active  := CheckBox5.Checked;
end;



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



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

end.
