Page 1 of 1

How to use ZoomRect with CustomAxis?

Posted: Tue Jul 17, 2007 8:06 am
by 9349911
Hi !

I have some customaxis in my chart which need to bee zoomed.
In the OnZoom Event I use this code:

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
var Achse   : TChartAxis;
    i       : Byte;
begin
 if Chart1.Zoom.Direction in [tzdBoth, tzdVertical] then

  for i := 0 to Chart1.SeriesCount - 1 do begin
    Achse := Chart1.Series[i].GetVertAxis;
    if Achse.Visible then
      Achse.SetMinMax(Achse.CalcPosPoint(Chart1.Zoom.Y1),Achse.CalcPosPoint(Chart1.Zoom.Y0));
  end;  
end;
If I try to zoom in / Zoom out with the ZoomRect function the chart alsways zoom out.

I use the sample from your helpfile:
Zoom in example:

Code: Select all

Chart1.ZoomRect( Rect( 5,5,Chart1.Width-5,Chart1.Height-5 ) );
Zoom out example:

Code: Select all

Chart1.ZoomRect( Rect( -5,-5,Chart1.Width+5,Chart1.Height+5 ) );
What must I do in order to zoom in and zoom out correctly the axis using ZoomRect ?

Posted: Tue Jul 17, 2007 9:21 am
by Pep
Hi Dominik,

have you tried using similar code to the following ?

Code: Select all

  procedure TForm1.FormCreate(Sender: TObject);
    var tmp: TChartAxis;
  begin
      Series1.FillSampleValues(20);
      tmp := (Chart1.CustomAxes.Add as TChartAxis);
      tmp.OtherSide:=true;
      tmp.Horizontal:=false;
      tmp.PositionPercent:=20;
      Series1.CustomVertAxis:=tmp;
  end;

  procedure TForm1.Chart1Zoom(Sender: TObject);
  begin
    With Series1.GetVertAxis 
      SetMinMax(CalcPosPoint(Chart1.IZoom.Y1),CalcPosPoint(Chart1.IZoom.Y0));
  end;

  procedure TForm1.Chart1UndoZoom(Sender: TObject);
  begin
    Series1.GetVertAxis.Automatic:=true;
  end;

Posted: Tue Jul 17, 2007 9:56 am
by 9349911
Hi Pep !

This won´t work for me.

I´ve uploaded a small demo appilcation to your server:
Received ZoomRect Test.zip Content Type application/x-zip-compressed Length 13796
Zoomin and Zoomout always does the same.

Posted: Fri Jul 20, 2007 9:27 am
by 9349911
Hi Pep,

did you checked my demo application ?

Posted: Sun Jul 22, 2007 11:42 am
by 9047589
On request of Dominik I post here a piece of my code using ZoomRect

Code: Select all

      
..
//From OnMouseWheel hanlder
if WheelDelta>0 then
        ZoomPercentage:=ZoomInRate*WheelDelta
      else
        ZoomPercentage:=ZoomOutRate*WheelDelta;
      with ChartRect do
        InflateRect(ChartRect,Round((Right-Left)*ZoomPercentage/100),Round((Bottom-Top)*ZoomPercentage/100));
      ZoomRect(ChartRect);

//From UndoZoomHandler
 with ParentChart, CustomAxes do
 for iX:=0 to Count-1 do
 with Items[iX] do
   Automatic:=True;

Posted: Mon Jul 23, 2007 6:31 am
by 9349911
Hi xxxxxx,

could you please add some information for the variables?

ZoomInRate, ZoomOutRate What value do you use for this?
ChartRect How if it defined and how to set the values?

Posted: Mon Jul 23, 2007 7:02 am
by 9349911
Hi !

I tried this:

Code: Select all

procedure TForm1.Chart1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var 
  ZoomInRate, ZoomOutRate     : double;
  ChartRect : TRect;
begin
if ([ssShift,ssCtrl] <= Shift) then begin
  ZoomInRate  := 2;
  ZoomOutRate := 2;
  ChartRect := Rect( 0,0,Chart1.Width,Chart1.Height);
  if WheelDelta>0 then
    ZoomPercentage:=ZoomInRate*WheelDelta
  else
    ZoomPercentage:=ZoomOutRate*WheelDelta;
  with ChartRect do
    InflateRect(ChartRect,Round((Right-Left)*ZoomPercentage/100),Round((Bottom-Top)*ZoomPercentage/100));
  Chart1.ZoomRect(ChartRect);
end;
end;
This won´t work for me. Could you please post an example of your whole Chart1MouseWheel procedure?