What is the difference between CalcXPos and XScreenToValue?
I am using DrawZoomRectangle to draw a boxes on the screen (TColorGridSereis) and want to remember where the box is so that when the screen is resized (or Zoomed), I can redraw it in the correct position.
As an example, in the Chart1MouseDown and Up events, I have the following code to grab the Top, Left, Bottom and Right points of the box...
// Calculate the left x index.
ind := Chart1.Series[0].XScreenToValue(X);
fIERRecList[Len].iX0 := ind;
fIERRecList[Len].Left := -1;
for i := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * i)) -
Abs(ind) < 0.00000001 then
begin
fIERRecList[Len].Left := Max(i-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
Then when the form is resized, I have code like this...
// Calculate X and Y positions on the new resized screen.
fIERRecList.zX0 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX0);
fIERRecList.zX1 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX1);
fIERRecList.zY0 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY0);
fIERRecList.zY1 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY1);
// Calculate the Left x index.
for j := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * j)) -
Abs(fIERRecList.iX0) < 0.00000001 then
begin
fIERRecList.Left := Max(j-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
// Now I can redraw the box.
What I am doing here is working, but seems very inefficient and slow. Since I use an axis offset and multiplier, I do not know how to calculate the information I need directly without the For Loop. Is there I better way to do this? Is my explanation clear?
CalcXPos and XScreenToValue
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi leaf,
XScreenToValue returns the numeric Value that corresponds to the specified Horizontal Screen coordinate. The resulting Value is based on the Series.GetHorizAxis.
So, XScreenToValue could return the bottom axis value based on the horizontal pixel screen coordinate returned by CalcXPos.
You could try using Locate method, its definition according to TeeChart help files is:
CalcXPos returns the pixel Screen Horizontal coordinate of the ValueIndex Series value.What is the difference between CalcXPos and XScreenToValue?
XScreenToValue returns the numeric Value that corresponds to the specified Horizontal Screen coordinate. The resulting Value is based on the Series.GetHorizAxis.
So, XScreenToValue could return the bottom axis value based on the horizontal pixel screen coordinate returned by CalcXPos.
What I am doing here is working, but seems very inefficient and slow. Since I use an axis offset and multiplier, I do not know how to calculate the information I need directly without the For Loop. Is there I better way to do this? Is my explanation clear?
You could try using Locate method, its definition according to TeeChart help files is:
function Locate(Const AValue: TChartValue): Integer;
This new function returns the corresponding point index which has the specified “Value”. You can use it to calculate X co-ordinates based on Y values or vice-versa:
tmp:=LineSeries1.XValues.Locate(EncodeDate(1996,1,1));
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi leaf,
Yes, Locate works fine in TColorGridSeries, try:
If you are still having problems, could you please send us an example we can run "as-is" to reproduce the problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
Yes, Locate works fine in TColorGridSeries, try:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var x,z: Integer;
begin
for x:=0 to 10 do
for z:=0 to 10 do
Series1.AddXYZ(x,x+z,z);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Chart1.Title.Text[0]:=IntToStr(Series1.XValues.Locate(6));
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |