unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, VclTee.TeeGDIPlus, VclTee.TeEngine,
VclTee.Series,
Vcl.ExtCtrls, VclTee.TeeProcs, VclTee.Chart, VclTee.BubbleCh,
System.Generics.Collections,
Vcl.StdCtrls;
type
TData =
class
private
FValX: Double;
FValY: Double;
FInfo:
string;
public
property ValX: Double
read FValX
write FValX;
property ValY: Double
read FValY
write FValY;
property Info:
string read FInfo
write FInfo;
end;
TForm1 =
class( TForm )
Chart1: TChart;
Series1: TPointSeries;
Button1: TButton;
procedure Chart1ClickSeries( Sender: TCustomChart; Series: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
procedure Button1Click( Sender: TObject );
procedure FormCreate(Sender: TObject);
private
FValues: TList<TData>;
procedure SetValues(
const Value: TList<TData> );
public
procedure BeforeDestruction;
override;
property Values: TList<TData>
read FValues
write SetValues;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BeforeDestruction;
begin
FreeAndNil( FValues );
inherited;
end;
procedure TForm1.Button1Click( Sender: TObject );
var
randomData: TObjectList<TData>;
I : Integer;
val : TData;
begin
randomData := TObjectList<TData>.Create;
for I := 1
to random( 50 ) + 10
do
begin
val := TData.Create;
val.ValX := random * 100;
val.ValY := random * 100;
val.Info := '
Data ' + I.ToString;
randomData.Add( val );
end;
Values := randomData;
end;
procedure TForm1.Chart1ClickSeries( Sender: TCustomChart; Series: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
begin
ShowMessage( Values[ ValueIndex ].Info );
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;
end;
procedure TForm1.SetValues(
const Value: TList<TData> );
var
val: TData;
begin
if FValues <> Value
then
begin
FValues.Free;
FValues := Value;
Series1.BeginUpdate;
try
Series1.Clear;
if Assigned( FValues )
then
begin
for val
in FValues
do
begin
Series1.AddXY( val.ValX, val.ValY, val.Info );
end;
end;
finally
Series1.EndUpdate;
end;
end;
end;
end.