Page 1 of 1

problem with calcXpos (also calcYpos)

Posted: Fri Oct 09, 2015 4:36 am
by 16475383
I need to draw a line using coordinates from a series of x,y points. The plot is fine but my attempt to draw a line fails when I use code like the following:
x1 :=Seriesxy.CalcXPos( ii-1 );
y1 :=Seriesxy.CalcYPos( ii-1 );
x2 :=Seriesxy.CalcXPos( jj-1 );
y2 :=Seriesxy.CalcYPos( jj-1 );
chart.Canvas.Line(x1, y1, x2, y2);

The problem is that the x1,y1, x2,y2 are equal to zero for all values of ii and jj even though the data values in the series are fine. I can look at them in debug mode. I also tried using :
x :=Seriesxy.XValues[ii-1];
x1 := seriesxy.CalcXPosValue( x );
The values of x are correct but x1 is still always equal to 0.

Is there some likely kind of error that I must be making?

Thanks, this is driving me a bit crazy!

Re: problem with calcXpos (also calcYpos)

Posted: Fri Oct 09, 2015 7:52 am
by yeray
Hello,

Note the Calc* functions need some internal variables to be initialized to wok properly (axes final position depending on the labels width, etc).
That's why we use to recommend forcing a chart repaint before using them (Chart1.Draw;).
On the other hand, for custom drawing functions you'll probably be interested on calling them at OnAfterDraw event or similar so they are called every time the chart is redrawn (note a zoom/scroll repaint the chart).

Re: problem with calcXpos (also calcYpos)

Posted: Sat Oct 10, 2015 1:31 am
by 16475383
That works! Thank you very much.