如何缩减的价值观,使他们能够适应里面的最小值和最大值 [英] How to scale down the values so they could fit inside the min and max values
问题描述
我有6个图形栏的价格。照片
每个价格数量将重新present其graphbar的高度尊重分
和最高
高度。
我想的是,图巴的高度将不会低于或 min以上
和最高
值。
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.
让我有值分= 55
和最大= 110
。
而价格数量
是:
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.
修改
因此,从价格表的最小值和最大值将是: 49(最低报价)=> 55(分钟)
和 1081(最高价)=> 110(最大)
Modified
So the min and max values from the price list will be: 49(min price) => 55(min)
and 1081 (max price) => 110(max)
推荐答案
解决方法很简单:
- 挑最小的,也是最大的项目,找到差异。
- (largest_item - smallest_item)映射到(最大值 - 最小值) 。
- 计算
率=(最大值 - 最小值)/(largest_item-smallest_item)
-
final_value = MIN_VALUE +比率*(价值smallest_item)
- Pick the smallest, and largest item and find the difference.
- (largest_item - smallest_item) maps to (max-min).
- Compute
ratio = (max-min)/(largest_item-smallest_item)
final_value = min_value + ratio*(value-smallest_item)
作为一个数学函数:
f(x,max,min,largest,smallest) = min + (max-min)/(largest-smallest)*(x-smallest)
where:
x : Input item's price
max: Maximum value (here, 110)
min: Minimum value (here, 55)
largest: Largest item in input (Here, 1081)
smallest: Smallest item in input (Here, 49)
一张支票,作为@amit正确地指出:确保最大和最小的项目是不同的。
One check, as @amit correctly points out: Ensure largest and smallest item are distinct.
因此,让X = 93,我们还有其他4个值与我们联系。
So let x = 93. We have other 4 values with us.
f(x,max,min,largest,smallest) = min + (max-min)/(largest-smallest)*(x-smallest)
value = 55 + ((110-55)/(1081-49)) * (93-49)
value = 57.344961
此外,
f(93,110,55,1081,49) = 57.344961
f(49,110,55,1081,49) = 55
f(1081,110,55,1081,49) = 110
这篇关于如何缩减的价值观,使他们能够适应里面的最小值和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!