本文介绍了计算“条形矩形”的比例因子的图表应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个整数值数组

  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 以像素为单位的条形图。

  • 值是要绘制的值。 code> max_value 是y轴的最大值。
  • chart_height 是图表的高度(像素为600)。



例如:

 88000/88000 = 1.0或图表高度的100%(600px)
0/88000 = 0或图表高度的0%(0px)
310 0/88000 =〜0.035,或图表高度的〜3.53%(〜21px)


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

解决方案
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)

这篇关于计算“条形矩形”的比例因子的图表应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:11