<canvas width="600" height="400"> </canvas>
<script>
    const pantalla = document.querySelector("canvas");
    const pincel = pantalla.getContext("2d");
    pincel.fillStyle = "#f2f4f4";
    pincel.fillRect(0, 0, 600, 400);
    function dibujarRectangulo(x, y, base, altura, color) {
        pincel.fillStyle = color;
        pincel.fillRect(x, y, base, altura);
        pincel.strokeStyle = "black";
        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, serie, color, texto) {
        escribirTexto(x, y - 10, texto);
        for (var i = 0; i < serie.length; i++) {
            dibujarRectangulo(x, y, 50, serie[i], color[i]);
            y = y + serie[i];
        }
    }
    var serie2009 = [6, 47, 41, 3, 3];
    var serie2019 = [81, 9, 3, 3, 4];
    var colores = ["blue", "green", "yellow", "red", "gray"];
    dibujarBarra(50, 50, serie2009, colores, "2009");
    dibujarBarra(150, 50, serie2019, colores, "2019");
</script>