Clipping problem with Chart1.Canvas.LineTo & AfterDrawVa

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Clipping problem with Chart1.Canvas.LineTo & AfterDrawVa

Post by pssdelphi » Tue Dec 19, 2006 8:04 pm

I have a pointer series on a chart, and I am drawing custom lines from certain points to others (not like the sequential point to point ones that are built in). The lines draw fine and scroll with the chart but they do not clip at the axis like the points in the series do. How can I get my custom lines to clip like the points in the series do?

Code: Select all

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
var x0, y0, x1, y1, x2, y2 : Integer ;
begin
Chart1.ClipPoints:=true;
x0:=Series1.CalcXPos(0);
y0:=Series1.CalcYPos(0);
x1:=Series1.CalcXPos(1);
y1:=Series1.CalcYPos(1);
x2:=Series1.CalcXPos(2);
y2:=Series1.CalcYPos(2);
Chart1.Canvas.MoveTo( x0, y0 );
Chart1.Canvas.LineTo( x1, y1 );
Chart1.Canvas.MoveTo( x0, y0 );
Chart1.Canvas.LineTo( x2, y2 );
end;

Thanks in advance,
David

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

Post by Pep » Sat Dec 23, 2006 1:26 pm

Hi David,

you can do :

Code: Select all

implementation

{$R *.dfm}

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
var x0, y0, x1, y1, x2, y2 : Integer ;
begin 
Chart1.ClipPoints:=true;
x0:=Series1.CalcXPos(0);
y0:=Series1.CalcYPos(0);
x1:=Series1.CalcXPos(1);
y1:=Series1.CalcYPos(1); 
x2:=Series1.CalcXPos(2);
y2:=Series1.CalcYPos(2);
Chart1.Canvas.MoveTo( x0, y0 );
Chart1.Canvas.LineTo( x1, y1 );
Chart1.Canvas.MoveTo( x0, y0 );
Chart1.Canvas.LineTo( x2, y2 );

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.BeforeDrawValues:=SeriesBeforeDraw;
end;

procedure TForm1.SeriesBeforeDraw(Sender: TObject);

  Function SeriesRect(Series:TChartSeries):TRect;
  begin
    With result do
    begin
      Left:=Series.GetHorizAxis.IStartPos;
      Right:=Series.GetHorizAxis.IEndPos;
      Top:=Series.GetVertAxis.IStartPos;
      Bottom:=Series.GetVertAxis.IEndPos;
    end;
  end;

begin
  // Clip
  With Chart1 do
       if CanClip then
          Canvas.ClipRectangle(SeriesRect( Sender as TChartSeries ));
end;
end.

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Sun Dec 31, 2006 3:35 am

Thanks

Marc
Site Admin
Site Admin
Posts: 1012
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Clipping problem with Chart1.Canvas.LineTo & AfterDrawVa

Post by Marc » Thu Jul 01, 2021 9:15 am

Hello,

Update to previous answer. The Clip in OnAfterDraw should apply to the Chart rectangle.

ie.

Code: Select all

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
var x0, y0, x1, y1, x2, y2 : Integer ;
begin
Chart1.Canvas.ClipRectangle(Chart1.ChartRect);  //<--here

x0:=Series1.CalcXPos(0);
y0:=Series1.CalcYPos(0);
x1:=Series1.CalcXPos(20); ...etc

Chart1.Canvas.UnClipRectangle;
Regards,
Marc Meumann
Steema Support

Post Reply