CalcXPosValue and CalcYPosValue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
dave
Newbie
Newbie
Posts: 13
Joined: Mon Feb 29, 2016 12:00 am

CalcXPosValue and CalcYPosValue

Post by dave » Fri Apr 29, 2016 7:34 pm

Can you think of any reason why the functions CalcXPosValue and CalcYPosValue would give different answers by simply re-sizing the window a chart is in and rerunning the same data? If I do not resize the window, I get the same answer every time. But if I change the window size (like maximize it) I get a different answer. I made an example executable to send you to demonstrate the issue, but the example didn't have the problem. So, I must be doing something different in my application that is not happening in the example, maybe not initializing something or setting something in the chart wrong.

I am using a tColorGridSeries and trying to find a point in my data set like (-3,3) on the right and top axes when the bottom and top where loaded with 1 through n like this:

Code: Select all

sx := chart1.axes.top.CalcXPosValue(PlotParam.IER_2D_Region[i].RotatedPoly[j].X);
sy := chart1.axes.right.CalcYPosValue(PlotParam.IER_2D_Region[i].RotatedPoly[j].Y);

// Get the data array index of the point.
k := Chart1.Series[0].Clicked(sx, sy);

r := k div (Chart1.Series[0] as TColorGridSeries).NumZValues;
c := k mod (Chart1.Series[0] as TColorGridSeries).NumZValues;
Thanks in advance,
dave

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: CalcXPosValue and CalcYPosValue

Post by Yeray » Mon May 02, 2016 8:23 am

Hello,
dave wrote:Can you think of any reason why the functions CalcXPosValue and CalcYPosValue would give different answers by simply re-sizing the window a chart is in and rerunning the same data?
That's correct if the chart is resized with the window. Note the CalcXPosValue/CalcYPosValue methods transform series values (doubles) to screen pixels (integers). If you resize the chart, the axes are resized and so do the distances in pixels.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

dave
Newbie
Newbie
Posts: 13
Joined: Mon Feb 29, 2016 12:00 am

Re: CalcXPosValue and CalcYPosValue

Post by dave » Mon May 02, 2016 12:52 pm

Yeary,

Thanks for your response. I agree with what you said. But, look at the rest of the example code and can you explain to me why r and c would be different after executing

Code: Select all

// Get the data array index of the point.
k := Chart1.Series[0].Clicked(sx, sy);

// Get the index into the 2D array that was used to load the chart.
r := k div (Chart1.Series[0] as TColorGridSeries).NumZValues;
c := k mod (Chart1.Series[0] as TColorGridSeries).NumZValues;
Even though sx and sy are different for the reasons you state, r and c should be the same if the data is loaded into the chart the same way. Is that not correct? And if this is correct, what do you think is causing it to be different? If I generate the plot, look at r and c then re-size the window and look at r and c for the same point, they are different.

thanks

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: CalcXPosValue and CalcYPosValue

Post by Yeray » Tue May 03, 2016 9:25 am

Hello,

It could be due to what these calls return:
dave wrote:sx := chart1.axes.top.CalcXPosValue(PlotParam.IER_2D_Region.RotatedPoly[j].X);
sy := chart1.axes.right.CalcYPosValue(PlotParam.IER_2D_Region.RotatedPoly[j].Y);

First of all note for this to work, your series has to have top and right axes assigned and visible (by default the axes assigned are left and bottom).
Also note I don't know what PlotParam is so I can't run your code as is here.

What I've done is a simple example, with just a chart in a form and this code, and it seems to work as expected for me here:

Code: Select all

uses TeeSurfa;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var k, r, c: Integer;
begin
  k := Chart1.Series[0].Clicked(X, Y);

  r := k div (Chart1.Series[0] as TColorGridSeries).NumZValues;
  c := k mod (Chart1.Series[0] as TColorGridSeries).NumZValues;

  Caption:='X: ' + IntToStr(X) + ', Y: ' + IntToStr(Y) +
  ', k: ' + IntToStr(k) +
  ', r: ' + IntToStr(r) + ', c: ' + IntToStr(c);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;
  Chart1.View3D:=false;

  Chart1.AddSeries(TColorGridSeries).FillSampleValues();
end;
If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.

Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply