0
我有整型數組值計算比例係數表應用程序「欄中矩形」
String[] values={3100,7500,8000,4200,88000,71000,32000};
需要進行縮放,以我的JComponent
的已知高度的,問題是如何擴大這些值進入例如H = 600px的?
這裏是一個事先知情同意只是爲了更清楚地瞭解我想要實現:
感謝
我有整型數組值計算比例係數表應用程序「欄中矩形」
String[] values={3100,7500,8000,4200,88000,71000,32000};
需要進行縮放,以我的JComponent
的已知高度的,問題是如何擴大這些值進入例如H = 600px的?
這裏是一個事先知情同意只是爲了更清楚地瞭解我想要實現:
感謝
bar_height = chart_height*(value/max_value)
要確定bar_height
,您縮放通過(value/max_value)
,其中(乘)chart_height
:
bar_height
是以像素爲單位的條的高度。value
是要繪製的值。max_value
是y軸上的最大值。chart_height
是以像素爲單位的圖表高度(在本例中爲600)。例如:
88000/88000 = 1.0, or 100% of the chart height (600px) 0/88000 = 0, or 0% of the chart's height ( 0px) 3100/88000 = ~0.035, or ~3.53% of the chart's height (~21px)
謝謝,但請你給我解釋一下你是怎麼想出這個公式?比例因子與它有關嗎? – skystar7 2011-04-09 03:22:22
我編輯了我的答案以添加解釋和示例。 – titaniumdecoy 2011-04-09 03:32:06
我看到他們謝謝,很好的解釋 – skystar7 2011-04-09 05:18:19