Page 1 of 1

pixels to value conversion

Posted: Mon Dec 08, 2008 8:45 pm
by 9334475
Hi,
I need to specify shape (circle) size in axis values, based on required size in pixels (e.g. 20px).

There are functions available like XScreenToValue / YScreenToValue which can help in that regard like:

size:=XScreenToValue(20)-XScreenToValue(0);

Is there a direct function converting pixels to axis value? (I know there is a reverse function Size->Pixels)

regards,
odissey1

Posted: Tue Dec 09, 2008 1:12 am
by 8574101
You can use CalcXPosValue() as following

int X0 = Chart1->Axes->Bottom->CalcXPosValue( 100 );
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);

Posted: Tue Dec 09, 2008 2:46 am
by 9334475
8574101 wrote:You can use CalcXPosValue() as following

int X0 = Chart1->Axes->Bottom->CalcXPosValue( 100 );
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Nope, that won't work, X:=CalcXPosValue(Val) is an integer and returns chart point 'X' position for a given axis value 'Val'.


I am looking for a function inverse to CalcSizeValue:
dX:=Chart1.BottomAxis.CalcSizeValue(Val);

something like
Val:=Chart1.BottomAxis.CalcValueSize(dX);


For example, for pixel size 20 this can be achieved as
Val:=Chart1.BottomAxis.CalcPosPoint(20)-Chart1.BottomAxis.CalcPosPoint(0);

or like this :)
Val:=20 * 1000000.0 / Chart1.BottomAxis.CalcSizeValue(1000000);

But why there is no any straight function?

Posted: Tue Dec 09, 2008 12:22 pm
by narcis
Hi odissey1,

What about this?

Code: Select all

  Val:=Chart1.Axes.Bottom.IStartPos + 20;

Posted: Tue Dec 09, 2008 6:48 pm
by 9334475
narcis wrote:Hi odissey1,

What about this?

Code: Select all

  Val:=Chart1.Axes.Bottom.IStartPos + 20;
Nope, this is not it. The result should be a Float, not an integer.

Let me re-phrase my question:
I nedd a Bubble point with radius 20pix. Let say that the BottomAxis spans from 0 to 100 units. What Radius value shoud I assign to a Bubble series to obtain a desired 20 pixels on the screen?

odissey1

Posted: Wed Dec 10, 2008 9:03 am
by narcis
Hi odissey1,

Thanks for the info.

In that case you can do something like this:

Code: Select all

  pos:=Chart1.Axes.Bottom.IStartPos + 20;
  val:=Chart1.Axes.Bottom.CalcPosPoint(pos);
  radius:=val-Chart1.Axes.Bottom.Minimum;
Where pos is an Integer and val and radius are Double variables.

Hope this helps!