Page 1 of 1

Zooming from Outside Chart axes

Posted: Mon Jan 18, 2016 11:25 am
by 16561419
Hello,

often when a range that needs to be zoomed in is close to an axis its not easy to achieve because the zoom rectangle can
only be started inside the chart axes area. Is there a simple option to enable the zoom rectangle to start outside the TChart axes ?

best regards,

X-ray

Re: Zooming from Outside Chart axes

Posted: Mon Jan 18, 2016 3:10 pm
by yeray
Hello,

You can Activate the Zoom and Panning at the OnClickBackground event as follows:

Code: Select all

procedure TForm1.Chart1ClickBackground(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with Chart1 do
  begin
    if Zoom.Allow and (Button=Zoom.MouseButton) and
       (Zoom.KeyShift<=Shift) then
    Begin
      if Zoom.Direction=tzdVertical then x:=ChartRect.Left;
      if Zoom.Direction=tzdHorizontal then y:=ChartRect.Top;

      Zoom.Activate({$IFDEF FMX}Round{$ENDIF}(x),{$IFDEF FMX}Round{$ENDIF}(y));

      if Zoom.Direction=tzdVertical then
         Zoom.X1:={$IFDEF FMX}Round{$ENDIF}(ChartRect.Right);

      if Zoom.Direction=tzdHorizontal then
         Zoom.Y1:={$IFDEF FMX}Round{$ENDIF}(ChartRect.Bottom);
    end;

    if (AllowPanning<>pmNone) and (Button=ScrollMouseButton) and
       (TeeScrollKeyShift<=Shift ) then
    Begin
      Panning.Activate({$IFDEF FMX}Round{$ENDIF}(x),
                       {$IFDEF FMX}Round{$ENDIF}(y));
    end;

    CancelMouse:=false;
  end;
end;

Re: Zooming from Outside Chart axes

Posted: Tue Jan 19, 2016 7:02 am
by 16561419
Hello Yeray,

very useful, thank You !
In fact it would be nice if this was just another flag/option of TChart.

best regards,

X-Ray

Re: Zooming from Outside Chart axes

Posted: Tue Jan 19, 2016 9:47 am
by yeray
Hello,

Ok. I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1408