问题
I have an array of integer values
String[] 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:
Thanks
回答1:
bar_height = chart_height*(value/max_value)
To determine bar_height, you scale (multiply) chart_height by (value/max_value), where:
bar_heightis the height of the a bar in pixels.valueis the value to be charted.max_valueis the maximum value on the y-axis.chart_heightis 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)
来源:https://stackoverflow.com/questions/5602644/calculating-the-scale-factor-for-bar-rectangles-of-chart-app