I need help with calibration of ADXL335. Is it possible to automatically calibrate it with respect to the position of the sensor?

I have manually obtained the maximum and minimum values for x, y and z axes by logging the data.
I have tried mapping the values using the map function but the results are incorrect.

Please help. I have read a few posts, but I am lost…

I got the raw maximum and minimum values of all the axes, but in particular I was trying to calibrate the sensor in the '-Y axis', and hence mapped the value using map(value_x, 501, 508, 511,518), where 501 and 508 were the min and max values of X axis in the '-Y' axis and 511 and 518 for the Z axis.

I don't think I am doing it right. I get weird results, with the raw values (supposedly mapped) exceed the limits i.e, around 700 for one of the axes.