Page 1 of 1

How to synchronize the zoom range of multiple charts

Posted: Thu Aug 19, 2004 2:15 pm
by 9337437
Is there a simple solution to synchronize the zoom ranges of multiple charts?
I want that if one chart is zoomed the other charts show the same zoom range.

thanks in advance,

Thomas

Posted: Thu Aug 19, 2004 4:10 pm
by Marjan
Hi, Thomas.
Yes, this can be done. All you have to do is capture one chart axis scale (minimum and maximum) and then use these values for other chart axes. You can check for axis scale in chart OnZoom, OnUndoZoom and OnScroll events and then use this info for other chart axes. Something like this (for three charts):

Code: Select all

Procedure AssignScales(Source,Dest:TCustomChart);
begin
  With Source.Axes.Bottom do Dest.Axes.Bottom.SetMinMax(Minimum,Maximum);
  With Source.Axes.Left do Dest.Axes.Left.SetMinMax(Minimum,Maximum);
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
     AssignScales(Chart1,Chart2);
     AssignScales(Chart1,Chart3);
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
     AssignScales(Chart1,Chart2);
     AssignScales(Chart1,Chart3);

end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
     AssignScales(Chart1,Chart2);
     AssignScales(Chart1,Chart3);
end;

procedure TForm1.Chart2Zoom(Sender: TObject);
begin
     AssignScales(Chart2,Chart1);
     AssignScales(Chart2,Chart3);

end;

procedure TForm1.Chart2UndoZoom(Sender: TObject);
begin
     AssignScales(Chart2,Chart1);
     AssignScales(Chart2,Chart3);
end;

procedure TForm1.Chart2Scroll(Sender: TObject);
begin
     AssignScales(Chart2,Chart1);
     AssignScales(Chart2,Chart3);
end;