条形图正在处理中,尺寸不对

Bar Chart in processing, I can't get the size right

我应该使用数组中的元素绘制二维条形图。 我必须根据值的总数和总 window 宽度来选择条形宽度;以及根据其特定值和所有元素的最大值计算的条形高度,考虑到最大值元素的条形高度将成为 window 的高度。 到目前为止,这是我的代码,但我没有得到我想要的结果。

float[] values = {25.0, 45.0, 5.0, 15.0, 10.0};

void setup() {
size(400,400);
}
void draw() {
background(0);

 // draw axes (relative to screen edges)
  stroke(255,0,0);
  strokeWeight(5);
  line(0,height,width,height);
  line(0,0,0,height);

    barChart(values);
}

void barChart(float[] data){
  for (int x=0; x<400; x+=80) {    
    for (int i=0; i<data.length; i++){

      fill(20,128,55);
    rect(x,350,80,(data[i]/100)*400);  //x,y,width,height
      }
    }

}


您写过条形宽度应该是 "function of the total number of values and the total window width" 但现在它是一个常量 (80)。

您还写道,条形高度应该是 "function of its particular value and the maximum value of all the elements, taking into account that the height of the bar of the element of maximum value is going to be the height of the window",但现在它只取决于数据值。

当然,代码 不能 做你期望它做的事,你需要将这些常量更改为基于这些变量的表达式。请这样做,如果您仍然得到意想不到的结果,请写下您的具体操作、您期望的输出以及结果有何不同。