Hi
Whilst I would like to allow my user to be able to zoom and scroll within a series of a chart, is there anyway that I can restrict a user from scrolling or zooming beyond/outside the extents of a series maximum and minimum xvalues??
I know this must be obvious but I just wondered if you could do it without writing a lot of additional code.
Bruce.
Restricting zooming and scrolling
Re: Restricting zooming and scrolling
Hi Bruce,
You can use the OnZoom and OnScroll events to limit it. Ie:
However, this would disable the zoom and you won't be able to unzoom.
An alternative would be to use the zoom history. When the condition is reached you can restore the last axes values. This way you won't zoom more than desired:
Or you can do it manually, if you want to avoid saving the history and directly jump to the initial state when you unzoom after several zooms:
You can use the OnZoom and OnScroll events to limit it. Ie:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Chart1.AddSeries(TPointSeries).FillSampleValues;
end;
procedure TForm1.Chart1Zoom(Sender: TObject);
begin
if Chart1.Axes.Bottom.Maximum-Chart1.Axes.Bottom.Minimum<5 then
Chart1.Zoom.Allow:=false;
end;
An alternative would be to use the zoom history. When the condition is reached you can restore the last axes values. This way you won't zoom more than desired:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Chart1.AddSeries(TPointSeries).FillSampleValues;
Chart1.Zoom.History:=true;
end;
procedure TForm1.Chart1Zoom(Sender: TObject);
begin
if Chart1.Axes.Bottom.Maximum-Chart1.Axes.Bottom.Minimum<5 then
with Chart1.Zoom.AxesHistory.Items[Chart1.Zoom.AxesHistory.Count-1] do
Chart1.Axes.Bottom.SetMinMax(AxesMinMax[6], AxesMinMax[7]);
end;
Code: Select all
uses Series;
var bottomMin, bottomMax: Double;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Chart1.AddSeries(TPointSeries).FillSampleValues;
bottomMin:=-1;
bottomMax:=-1;
end;
procedure TForm1.Chart1Zoom(Sender: TObject);
begin
if Chart1.Axes.Bottom.Maximum-Chart1.Axes.Bottom.Minimum<5 then
if (bottomMin<>-1) and (bottomMax<>-1) then
Chart1.Axes.Bottom.SetMinMax(bottomMin, bottomMax)
else
Chart1.Axes.Bottom.SetMinMax(Chart1.Axes.Bottom.Minimum, Chart1.Axes.Bottom.Minimum+5);
bottomMin:=Chart1.Axes.Bottom.Minimum;
bottomMax:=Chart1.Axes.Bottom.Maximum;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Restricting zooming and scrolling
Thanks Yeray I'll give that a go!