Page 1 of 1

Locating ends of a DLine in Pixels.

Posted: Wed May 29, 2013 5:24 pm
by 13052810
Hi,

I've drawn a DrawLine on my graph, so now how do I find the ends in pixels?

I'm pretty sure this is easy, I'm just not seeing it...

Thanks!

Re: Locating ends of a DLine in Pixels.

Posted: Thu May 30, 2013 2:40 pm
by yeray
Hi,

Being ChartTool1 your TDrawLineTool, and being the line you want to check the one with index 0, the positions in axis values are:

Code: Select all

ChartTool1.Lines[0].StartPos.X
ChartTool1.Lines[0].StartPos.Y
ChartTool1.Lines[0].EndPos.X
ChartTool1.Lines[0].EndPos.Y
Then, you should use the axes CalcPosValue function to transform axis values to pixels. Ie:

Code: Select all

XStartPixel:=Chart1.Axes.Bottom.CalcPosValue(ChartTool1.Lines[0].StartPos.X);
YStartPixel:=Chart1.Axes.Left.CalcPosValue(ChartTool1.Lines[0].StartPos.Y);

Re: Locating ends of a DLine in Pixels.

Posted: Mon Jun 03, 2013 3:58 pm
by 13052810
Thanks Yeray!

Re: Locating ends of a DLine in Pixels.

Posted: Mon Jun 03, 2013 10:51 pm
by 13052810
Ok,

The above code does give me the info I need, however, it doesn't seem to give me the info I need when the Zoom function has been used.

When zooming in on an end of the DLine, the resulting view is expanded, but the CalcXPosValue(a) and CalcYPosValue(a) returns the same pixel value(s) as when the view is not Zoomed.

I can't figure out what parameter(s) are changed when the Zoom function is used.
Is there a "ZoomXFactor, ZoomYFactor" I can access?
Can you assist?

Thanks!

Re: Locating ends of a DLine in Pixels.

Posted: Tue Jun 04, 2013 9:59 am
by yeray
Hi,

Try forcing a chart repaint:

Code: Select all

TChart1.Environment.InternalRepaint
at the beginning of the OnZoom event. After it, the chart should have updated its internal values and the Calc* functions should work fine then.

Re: Locating ends of a DLine in Pixels.

Posted: Tue Jun 04, 2013 2:55 pm
by 13052810
Thanks Yeray!
That solved the problem.