xxxxxxxxxx
41
function preload() {
// Load the data
table = loadTable('data.csv', 'csv', 'header');
}
function setup() {
createCanvas(400, 250);
noLoop();
}
function draw() {
// Calculate the width and the height of the bars
bars = table.getRowCount();
barWidth = width / bars;
barHeight = height;
// Loop over the data
for (let i = 0; i < bars; i++) {
// Calculate the position of the bar
x = i * barWidth;
y = 0;
// Calculate the color of the bar
d = table.get(i,1);
if (d > 0) {
col = lerpColor(color("white"), color("red"), d);
} else {
col = lerpColor(color("white"), color("blue"), -d);
}
fill(col);
noStroke();
// Draw the bar
rect(x, y, barWidth, barHeight);
}
}