<canvas width="600" height="400"></canvas>
<script>
let pantalla = document.querySelector("canvas");
let pincel = pantalla.getContext("2d");
let serie2009 = [6, 47, 41, 3, 3];
let serie2019 = [81, 9, 3, 3, 4];
let colores = ["blue", "green", "yellow", "red", "gray"];
function dibujarRect(x, y, base, altura, color) {
pincel.fillStyle = color;
pincel.strokeStyle = "black"
pincel.fillRect(x, y, base, altura);
pincel.strokeRect(x, y, base, altura);
}
function escribirTexto(x, y, texto) {
pincel.font = "15px Georgia";
pincel.fillStyle = "black";
pincel.fillText(texto, x, y);
}
function dibujarBarra(x, y, base, serie, colores, titulo) {
let distanciaY = 20;
escribirTexto(x, y, titulo);
for (let index = 0; index < serie.length; index++) {
dibujarRect(x, y + distanciaY, base, serie[index], colores[index]);
distanciaY += serie[index];
}
}
dibujarBarra(50, 50, 60, serie2009, colores, "2009");
dibujarBarra(150, 50, 60, serie2019, colores, "2019");
</script>