Hi moelski,
Well this seems to be tricky ....
Would it be possible to do calculate the new position a little bit more dynamically? Here are my problems:
1) What will happend if series1 isn´t visible?
2) What will happen if no series is visible?
This is dynamic because whenever the chart is zoomed or scrolled the rectangle position is changed accordingly as well. However this is just an example. If you don't relate rectangle's position to series you can make it relative to chart axes for example:
Code: Select all
procedure TForm1.SetRectPos;
begin
Chart1.Draw;
ChartTool1.Shape.CustomPosition:=true;
ChartTool1.Shape.Left:=Chart1.Axes.Left.PosAxis + 10;
ChartTool1.Shape.Top:=Chart1.Axes.Bottom.PosAxis - 10;
end;
I have tried to use your code in this way:
Code:
TRectangleTool(Chart1.Tools[1]).Shape.Left := Series1.CalcXPos(TRectangleTool(Chart1.Tools[1]).Shape.Left);
TRectangleTool(Chart1.Tools[1]).Shape.Top := Series1.CalcYPos(TRectangleTool(Chart1.Tools[1]).Shape.Top);
But this won´t work for me.
CalcXPos and CalcYPos methods doesn't work that way. Those methods return a pixel screen position from given series point ValueIndex. Look at the different methods provided for calculating from chart values to pixel screen coordinates and viceversa.
So could you please add a small piece of code which changes the position of the rectangle tool against it´s actual position.
A simple example would be something like this:
Code: Select all
procedure TForm1.SetRectPos;
begin
Chart1.Draw;
ChartTool1.Shape.CustomPosition:=true;
ChartTool1.Shape.Left:=ChartTool1.Shape.Left + 10;
ChartTool1.Shape.Top:=ChartTool1.Shape.Top - 10;
end;
Don't forget the Draw call in the SetRectPos method in all the examples I posted.
And what about the Callouts. Must I recalculate the endpoint, too?
Yes, the same for the callout needs to be done.