Aquí mi solución al ejercicio de las gráficas de barras, cualquier cometario (constructivo) es bienvenido...
<canvas width="600" height="400"></canvas>
<script>
var canvas = document.querySelector("canvas");
var brush = canvas.getContext("2d");
brush.fillStyle = "lightgray";
brush.fillRect(0, 0, 600, 400);
function drawRectangle(xPoint, yPoint, width, height, fill) {
brush.fillStyle = fill
brush.fillRect(xPoint, yPoint, width, height)
brush.strokeStyle = "black"
brush.strokeRect(xPoint, yPoint, width, height)
}
function printText(text, xPoint, yPoint) {
brush.font = "20px Georgia"
brush.fillStyle = "black"
brush.fillText(text, xPoint, yPoint)
}
const percents2009 = [6, 47, 41, 3, 3]
const percents2019 = [81, 9, 3, 3, 4]
const fills = ["blue", "green", "yellow", "red", "gray"]
function drawBargraph(title, xPoint, yPoint, percents, colors) {
printText(title, xPoint, yPoint - 10,)
if(percents.length === colors.length) {
for(i = 0; i < percents.length; i++) {
drawRectangle(xPoint, yPoint, 150, percents[i] * 3, colors[i])
yPoint += percents[i] * 3
}
}
}
drawBargraph("2009", 100, 50, percents2009, fills)
drawBargraph("2019", 350, 50, percents2019, fills)
</script>