开发者

Calculating the scale factor for "bar rectangles" of Chart app

I have an array of integer values

String[]开发者_如何学Go values={3100,7500,8000,4200,88000,71000,32000};

that need to be scaled into a known height of my JComponent , the question is how to scale these values into e.g. h=600px?

Here is a pic just for more clarification of what i want to achieve:

Calculating the scale factor for "bar rectangles" of Chart app

Thanks


bar_height = chart_height*(value/max_value)

To determine bar_height, you scale (multiply) chart_height by (value/max_value), where:

  • bar_height is the height of the a bar in pixels.
  • value is the value to be charted.
  • max_value is the maximum value on the y-axis.
  • chart_height is the height of the chart in pixels (600 in your example).

For example:

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜