<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLOR</title>
</head>
<body>
<canvas width="600" height="400">
</canvas>
</body>
<script>
const pantalla = document.querySelector('canvas');
const pincel = pantalla.getContext('2d');
const cuadrado = (x,y,ancho,alto,color,borde) => {
pincel.fillStyle = color;
pincel.fillRect(x,y,ancho,alto);
pincel.strokeStyle = borde;
pincel.strokeRect(x,y,ancho,alto)
}
cuadrado(0,0,600,400,"lightgray");
const 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);
}
const 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];
cuadrado(x, y + sumaAltura, 50, altura, colores[i]);
sumaAltura = sumaAltura + altura;
}
}
let serie2009 = [6, 47, 41, 3, 3];
let serie2019 = [81, 9, 3, 3, 4];
let colores = ["blue","green","yellow", "red","gray"];
dibujarBarra(50, 50, serie2009, colores, "2009");
dibujarBarra(150, 50, serie2019, colores, "2019");
</script>
</html>