Simple bar graph from an array
in
Programming Questions
•
6 months ago
Greetings. I am just learning Processing and I am tasked with creating a simple bar graph from a set numbers from an xcel spreadsheet. I believe I just need like a for or an if loop to have it create a bar for each of the values (where the value would be the height of the bar).
Below is my code. Right now I get all the bars to show up, but seem to overlap one another.
int[] coords;
void setup() {
size(500,500);
background(255);
fill(200,200,30,50);
String[] nums = loadStrings("numbers.csv");
coords = int(split(nums[0], ','));
} // end setup
void draw() {
//sets location for each bar, 50 units apart
for (int x = 0; x < 500; x = x + 50) {
//creates a counter for each of the values in the array
for (int i = 0; i < 10; i = i + 1){
//draws the rectangle for each of the values in the array to corresponding height
rect (x, 475, 30, -coords[i], 3);
}
}
} // end draw
1