How to use ZoomRect with CustomAxis?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

How to use ZoomRect with CustomAxis?

Post by moelski » Tue Jul 17, 2007 8:06 am

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 ?

Pep
Site Admin
Site Admin
Posts: 3299
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Jul 17, 2007 9:21 am

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;

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Tue Jul 17, 2007 9:56 am

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.

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Fri Jul 20, 2007 9:27 am

Hi Pep,

did you checked my demo application ?

xxxxxx
Advanced
Posts: 128
Joined: Tue Jun 19, 2007 12:00 am
Location: Russia
Contact:

Post by xxxxxx » Sun Jul 22, 2007 11:42 am

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;

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Mon Jul 23, 2007 6:31 am

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?

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Mon Jul 23, 2007 7:02 am

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?

Post Reply