Bar Graph Example from an Array
// Declaration & Initialization
int[] heights = new int[8];
int barwidth = 18;
int barspacing = 4;
 
void setup() {
size (200, 200);
 
// Assigning values in the array
heights[0] = 80;
heights[1] = 100;
heights[2] = 50;
heights[3] = 75;
heights[4] = 95;
heights[5] = 85;
heights[6] = 40;
heights[7] = 60;
 
colorMode(HSB, 360, 100, 100);
noStroke();
}
 
void draw() {
  //println(heights.length);
  background(0, 0, 30);
  fill(300, 50, 70);
  for (int i = 0; i < heights.length; i ++) {
    rect( barspacing + (i * (barspacing + barwidth)), height - heights[i],
    barwidth, heights[i]);
  }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License