Calculation of the scale factor for the "rectangle rectangles" of the Chart application

I have an array of integer values

String[] values={3100,7500,8000,4200,88000,71000,32000}; 

which need to be scaled to a known height of my JComponent , the question is how to scale these values, for example, h = 600px?

Here is a script for a more detailed explanation of what I want to achieve: enter image description here

thanks

0
source share
1 answer
 bar_height = chart_height*(value/max_value) 

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

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

For instance:

  88000/88000 = 1.0, or 100% of the chart height (600px)
     0/88000 = 0, or 0% of the chart height (0px)
  3100/88000 = ~ 0.035, or ~ 3.53% of the chart height (~ 21px) 
+3
source

All Articles