วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Bar Chart [Parallel Array]




void setup() {   
  size (550, 500); 
  background(#54BCB4);
}
float max;
float min;
float avr;
void draw () { 
  int x = 80; 
  int i = 0;
  int j = 0; 
  int v = 390;
  float [][] Bar = { 
    { 
      19.7, 21.9, 19.5, 19.0
    } 
    , 
    { 
      14.5, 14.0, 16.0, 15.5
    }
  }; 
  String [] Age = {
    "0-4", "5-9", "10-14", "15-17"
  };
  while (i < Bar[0].length) {
    textSize(10);
    fill(#1B2E86);
    rect (x, 320, 30, -Bar[0][i]*10);
    textSize(12);
    text(Bar[0][i]+"%", x, 350);
    fill(#B55ECE);
    rect (x+35, 320, 30, -Bar[1][j]*10);
    textSize(12);
    text(Bar[1][i]+"%", x+40, 350);
    fill(#D37180);
    textSize(14);
    text(Age[i]+"year", x+10, 97); 
    i = i + 1; 
    x = x + 100;

    textSize(17);
    fill (#280A3E);
    text("Number and percentage of child and youth aged 0 - 17 years ", 23, 30);
    text("according to living arrangements by living with parents 2008", 23, 50);
    while (j<=2) {
      if (Bar[i][j]<min) {
        min=Bar[i][j];
      }
      if (Bar[i][j]>max) {
        max=Bar[i][j];
      }
      j=j+1;
    }
  }

  fill(#1B2E86);
  rect(350, v, 15, 15);
  text("neither parent", 370, v+15);
  fill(#B55ECE);
  rect(350, v+20, 15, 15);
  text("mother only", 370, v+35);
  text("MAX: "+max, 150, v+15);
  text("MIN: "+min, 150, v+35);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น