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