Peter Pohlmann
Peter Pohlmann

Reputation: 1508

Recalculate values on different scale in chart

I want to display some values inside a chart-like tool based on pixels. Problem is that the left xAxis has a max scale of 200 pixel. Inside that pixel square i want to display different altitude values that can range from 200m-1500m or 324m-724m or anything else.

So i need to recalculate the orignal values by a factor to display them inside this chart. Haven't find the right solution yet. Any hints ?

enter image description here

Upvotes: 0

Views: 43

Answers (1)

MBo
MBo

Reputation: 80232

You have range of Y-coordinates 0..YMax (200 for your case) and data range Data_Low..Data_High (find min and max values).

To map data range to axis range, use linear formula:

Y = (Value - Data_Low) * YMax / (Data_High - Data_Low)

If axis starts from YMin, use

Y = YMin + (Value - Data_Low) * (YMax - YMin) / (Data_High - Data_Low)

Upvotes: 1

Related Questions