Page 1 of 1

Synchronizing charts and the UndoZoom event

Posted: Wed May 22, 2013 4:32 pm
by 10047857
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.

Re: Synchronizing charts and the UndoZoom event

Posted: Thu May 23, 2013 10:18 am
by yeray
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;

Re: Synchronizing charts and the UndoZoom event

Posted: Thu May 23, 2013 12:39 pm
by 10047857
Thanks once again Yeray!

Re: Synchronizing charts and the UndoZoom event

Posted: Thu May 23, 2013 2:50 pm
by yeray
Hi,

You're welcome, Bruce