2
respuestas

GRAFICO DE BARRAS:::

DE APOCO VOY ENTENDIENDO, PERO NO ESTA FACIL...

<canvas width="600" height="400"></canvas>

<script>
    function dibujarBarra(x, y, serie, colores, texto) {


}
    function dibujarRectangulo(x, y, base, altura, color) {
        var pantalla = document.querySelector("canvas");
        var pincel = pantalla.getContext("2d");

        pincel.fillStyle=color;
        pincel.fillRect(x,y, base, altura);
        pincel.strokeStyle="black";
        pincel.strokeRect(x,y, base, altura);
    }

    function escribirTexto(x , y, texto) {
        var pantalla = document.querySelector("canvas");
        var pincel = pantalla.getContext("2d");

        pincel.font="15px Georgia";
        pincel.fillStyle="black";
        pincel.fillText(texto, x, y); 
    }
    function dibujarBarra(x, y, serie, colores, texto) {

        escribirTexto(x, y - 10, texto);

        var sumaAltura = 0;
        for (var i = 0; i < serie.length; i++) {
        var altura = serie[i];
         dibujarRectangulo(x, y + sumaAltura, 50, altura, colores[i]);
        sumaAltura = sumaAltura + altura;
}
    }   var colores = ["blue","green","yellow", "red","gray"];
        var serie2009 = [6, 47, 41, 3, 3];
        var serie2019 = [81, 9, 3, 3, 4];

        dibujarBarra(50, 50, serie2009, colores, "2009");
        dibujarBarra(150, 50, serie2019, colores, "2019");

        </script>
2 respuestas

COMO AGO PARA AGREGAR MAS TEXTO ?

Hola Tomas , espero que esté bien.

Gracias por compartir tu código con nosotros, contínua con tu estudos :)

Si tienes alguna pregunta sobre el contenido de los cursos, estaremos aquí para ayudarte.

Si este post te ayudó, por favor, marca como solucionado ✓. Continúa con tus estudios