Synchronizing charts and the UndoZoom event

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Synchronizing charts and the UndoZoom event

Post by Metman » Wed May 22, 2013 4:32 pm

Hi

I have 3 charts on my form and as they all have the same range of xvalues I have synchronized them as regards zooming and scrolling. This works fine all except for OnUndoZoom event. Obviously when I reset the zoom for Chart1 I want to call the UndoZoom for the other two charts which I do, but of course doing this fires their UndoZoom event which then calls Chart1's UndoZoom event in a recursive loop. There must be an easy way round this can you help?

Bruce.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Synchronizing charts and the UndoZoom event

Post by Yeray » Thu May 23, 2013 10:18 am

Hi Bruce,

I'd suggest you to use flags to control this. Here you have an example:

Code: Select all

uses Series;

var zoom1, zoom2: boolean;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;
  Chart1.AddSeries(TPointSeries).FillSampleValues;

  Chart2.View3D:=false;
  Chart2.AddSeries(TPointSeries).DataSource:=Chart1[0];

  zoom1:=true;
  zoom2:=true;
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  if zoom1 then
  begin
    zoom1:=false;
    with Chart1.Zoom do
      Chart2.ZoomRect(Rect(X0, Y0, X1, Y1));
    zoom1:=true;
  end;
end;

procedure TForm1.Chart2Zoom(Sender: TObject);
begin
  if zoom2 then
  begin
    zoom2:=false;
    with Chart2.Zoom do
      Chart1.ZoomRect(Rect(X0, Y0, X1, Y1));
    zoom2:=true;
  end;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  if zoom1 then
  begin
    zoom1:=false;
    Chart2.UndoZoom;
    zoom1:=true;
  end;
end;

procedure TForm1.Chart2UndoZoom(Sender: TObject);
begin
  if zoom2 then
  begin
    zoom2:=false;
    Chart1.UndoZoom;
    zoom2:=true;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Synchronizing charts and the UndoZoom event

Post by Metman » Thu May 23, 2013 12:39 pm

Thanks once again Yeray!

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Synchronizing charts and the UndoZoom event

Post by Yeray » Thu May 23, 2013 2:50 pm

Hi,

You're welcome, Bruce
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply