I have 6 graph bars with the prices.
Each price number will represent its graphbar’s height by respecting min and max heights.
What i want is that graph bar’s height wouldn’t go below or above the min and the max value.
So i have values of min = 55 and max = 110.
And price numbers are:
- 49
- 212
- 717
- 1081
- 93
By which mathematical algorithm I could achieve expected results ?
It’s some sort of dynamic scalable bar graphs.
Modified
So the min and max values from the price list will be: 49(min price) => 55(min) and 1081 (max price) => 110(max)
The solution is simple:
ratio = (max-min)/(largest_item-smallest_item)final_value = min_value + ratio*(value-smallest_item)As a mathematical function:
One check, as @amit correctly points out: Ensure largest and smallest item are distinct.
So let x = 93. We have other 4 values with us.
Further,