uses
Math, TAChartUtils, TACustomSeries;
procedure TForm1.Chart1ExtentChanging(ASender: TChart);
var
ext: TDoubleRect;
i, j: Integer;
ymin, ymax: Double;
ser: TChartSeries;
x, y: Double;
begin
ext := Chart1.LogicalExtent;
// Find minimum and maximum y value of all series values for which the data points
// have an x value in the visible x extent.
// Convert to graph coordinates because they are needed by the chart's extent.
ymin := 1E308;
ymax := -1E308;
for i:=0 to Chart1.Series.Count-1 do
if Chart1.Series[i] is TChartSeries then begin
ser := TChartSeries(Chart1.Series[i]);
for j:=0 to ser.Count-1 do begin
x := ser.AxisToGraphX(ser.XValue[j]);
if InRange(x, ext.a.x, ext.b.x) then begin
y := ser.AxisToGraphY(ser.YValue[j]);
ymin := Min(ymin, y);
ymax := Max(ymax, y);
end;
end;
end;
ext.a.y := ymin;
ext.b.y := ymax;
Chart1.LogicalExtent := ext;
end;