Shape Series depens on calling sequence

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
gsachs
Newbie
Newbie
Posts: 2
Joined: Mon Apr 18, 2011 12:00 am

Shape Series depens on calling sequence

Post by gsachs » Fri Apr 13, 2012 5:25 pm

// This draws a correct shape
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.Clear;
Chart1.LeftAxis.SetMinMax( 0.0, 100.0 );
Chart1.BottomAxis.SetMinMax( 0.0, 100.0 );
Series1.X1 := 60;
Series1.Y1 := 50;
Series1.X0 := 20;
Series1.Y0 := 30;
end;


// Different sequence , draws an incorrect shape, see attached images
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.Clear;
Chart1.LeftAxis.SetMinMax( 0.0, 100.0 );
Chart1.BottomAxis.SetMinMax( 0.0, 100.0 );
Series1.X0 := 20;
Series1.Y0 := 30;
Series1.X1 := 60;
Series1.Y1 := 50;
end;

I use the shape series for reason that the rectangle tool does not size with zoom, which i need.
The shape series does size, but a shape is not movable or sizable with the mouse, which i need too.
Is there another way to honor both requirements ?

Regards
Gerhard
Attachments
TeeChart InCorrectShape.JPG
TeeChart InCorrectShape.JPG (41.59 KiB) Viewed 3328 times
TeeChart CorrectShape.JPG
TeeChart CorrectShape.JPG (38.74 KiB) Viewed 3339 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Shape Series depens on calling sequence

Post by Yeray » Mon Apr 16, 2012 12:29 pm

Hi Gerhard,

I think the easiest way to do this would be using a TRectangleTool. To zoom&scroll it with the chart, you could save the rectangle coordinates transformed to axes values (ie P0X, P0Y, P1X, P1Y) and redraw the tool with the reconverted values at OnZoom/OnUndoZoom/OnScroll events:

Code: Select all

uses Series, TeeTools, Math;

var P0X, P0Y, P1X, P1Y: Double;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TFastLineSeries);

  Chart1.Axes.Bottom.SetMinMax(0,100);
  Chart1.Axes.Left.SetMinMax(0,100);

  with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  begin
    Text:='my rectangle Tool';
    PositionUnits:=muPixels;
    OnDragged:=RectToolDragged;
    OnResized:=RectToolResized;
  end;

  P0X:=20;
  P0Y:=30;
  P1X:=60;
  P1Y:=50;

  redrawRectangleTool;
end;

procedure TForm1.redrawRectangleTool;
begin
  Chart1.Draw;
  with Chart1.Tools[0] as TRectangleTool do
  begin
    Left:=Chart1.Axes.Bottom.CalcPosValue(min(P0X,P1X));
    Top:=Chart1.Axes.Left.CalcPosValue(max(P0Y,P1Y));
    Width:=Chart1.Axes.Bottom.CalcSizeValue(abs(P1X-P0X));
    Height:=Chart1.Axes.Left.CalcSizeValue(abs(P1Y-P0Y));
  end;
end;

procedure TForm1.recalcRectangleTool(tool: TObject);
begin
  with tool as TRectangleTool do
  begin
    P0X:=Chart1.Axes.Bottom.CalcPosPoint(Left);
    P0Y:=Chart1.Axes.Left.CalcPosPoint(Top);
    P1X:=Chart1.Axes.Bottom.CalcPosPoint(Left+Width);
    P1Y:=Chart1.Axes.Left.CalcPosPoint(Top+Height);
  end;
end;

procedure TForm1.RectToolDragged(Sender: TObject);
begin
  recalcRectangleTool(Sender);
end;

procedure TForm1.RectToolResized(Sender: TObject);
begin
  recalcRectangleTool(Sender);
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  redrawRectangleTool;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  redrawRectangleTool;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  redrawRectangleTool;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

gsachs
Newbie
Newbie
Posts: 2
Joined: Mon Apr 18, 2011 12:00 am

Re: Shape Series depens on calling sequence

Post by gsachs » Tue Apr 17, 2012 3:51 pm

Hello Yeray,

thank you for the information.
I will change the Shape series to a rectangle tool.

But there is still the behaviour where the displayed shape depends on the parameter sequence.
For me, it is clear now.
But maybe other people would save some investigation time if such behaviour is documented.

Regards
Gerhard Sachs

Post Reply