Recent

Author Topic: [SOLVED] Print an arrow into a TAChart  (Read 3823 times)

donnie

  • Jr. Member
  • **
  • Posts: 72
[SOLVED] Print an arrow into a TAChart
« on: December 05, 2016, 01:55:49 pm »
Hi there,
I have drawn an arrow from a start point A(x0,y0 let's say 0,0) to an end point B(x1,y1). The shape of the arrow shows that direction from A to B (A->B). The code I used is this:
Code: Pascal  [Select][+][-]
  1. var Arrow1: TFieldSeries;
  2. .....
  3. begin  
  4.       Line1 := TLineSeries.Create(self);    
  5.       Chart1.AddSeries(Line1);
  6.      
  7.       Arrow1 := TFieldSeries.Create(self);
  8.       Chart1.AddSeries(Arrow1);
  9.  
  10.       for i := Low(Array1) to High(Array1) do
  11.         Line1.AddXY(Array1[i].y, Array2[i].y); // Array1 and Array2 have the same Length
  12.  
  13.       Arrow1.AddVector(Array1[High(Array1)].y/2, Array2[High(Array2)].y/2, Array1[High(Array1)].y, Array2[High(Array2)].y, '', $0000FF);
  14.       Arrow1.Pen.Width:=3;
  15.       Arrow1.Arrow.BaseLength := ArrowPView1.Arrow.Length;
  16.     end;
  17.  

As I want the arrow to start from (0,0) and end to the my last point I use the
Code: Pascal  [Select][+][-]
  1. Arrow1.AddVector(Array1[High(Array1)].y/2, Array2[High(Array2)].y/2, Array1[High(Array1)].y, Array2[High(Array2)].y, '', $0000FF);
When I draw the chart everything seems ok. But when I print the chart the arrow get too much bigger.
I believe that the problem must be the GraphToImage(DoublePoint(x1, y1)).
I also need to draw that arrow above all lines in the TAChart (so its Zposition must be the bigger).
« Last Edit: December 06, 2016, 09:06:36 am by donnie »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Print an arrow into a TAChart
« Reply #1 on: December 05, 2016, 02:33:17 pm »
Could you post a little demo showing the issue? Only pas, lfm, lpi and lpr files packed into common zip, please. And remove everything which is not needed to demonstrate the bug.

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: Print an arrow into a TAChart
« Reply #2 on: December 05, 2016, 03:27:32 pm »
Yes after a little hour I manage to keep the necessary.
Click Draw first and after that Print.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Print an arrow into a TAChart
« Reply #3 on: December 05, 2016, 04:13:00 pm »
Please try r53560. I had to modify your demo since I don't have two required packages (lz_report, lz_tachart - what are these?), but I think it is working now.

P.S.
Seems to be CodeTyphoon...
In this case my patch does not help you immediately. Open tamultiseries.pas, go to procedure TFieldSeries.DrawVector. After the line "if FArrow.Visible" there's an assignment to len. Divide this calculation by ADrawer.Scale(1). The entire DrawVector method should read:
Code: Pascal  [Select][+][-]
  1. procedure TFieldSeries.DrawVector(ADrawer: IChartDrawer;
  2.   AStartPt, AEndPt: TDoublePoint; APen: TPen);
  3. var
  4.   p1, p2: TPoint;
  5.   arr: TChartArrow;
  6.   len: Double;
  7. begin
  8.   p1 := ParentChart.GraphToImage(AStartPt);
  9.   p2 := ParentChart.GraphToImage(AEndPt);
  10.   ADrawer.Pen := APen;
  11.   ADrawer.Line(p1.x, p1.y, p2.x, p2.y);
  12.   if FArrow.Visible then begin
  13.     len := sqrt(sqr(p2.x - p1.x) + sqr(p2.y - p1.y)) * 0.01 / ADrawer.Scale(1);
  14.     // Be aware that the drawer scales pixels. But the arrow length here is
  15.     // already at the correct size!
  16.     arr := TChartArrow.Create(nil);
  17.     arr.Assign(FArrow);
  18.     arr.SetOwner(nil);  // avoid repainting due to next commands
  19.     arr.BaseLength := round(FArrow.BaseLength * len);
  20.     arr.Length := round(FArrow.Length * len);
  21.     arr.Width := round(FArrow.Width * len);
  22.     arr.Draw(ADrawer, p2, arctan2(p2.y-p1.y, p2.x-p1.x), APen);
  23.     arr.Free;
  24.   end;
  25. end;
« Last Edit: December 05, 2016, 04:19:06 pm by wp »

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: Print an arrow into a TAChart
« Reply #4 on: December 06, 2016, 09:04:43 am »
Yeap, exactly that!!!
Now the print is perfect.
You are the master of the chart my friend.
Thanks once again wp!!!
« Last Edit: December 06, 2016, 10:22:39 am by donnie »

 

TinyPortal © 2005-2018