<!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>GRAFICOS DE USO NAVEGADORES</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
function dibujarRectangulo(x, y, width, height, color) {
let pantalla = document.querySelector("canvas");
let pincel = pantalla.getContext("2d");
pincel.fillStyle=color;
pincel.fillRect(x,y, width, height);
pincel.strokeStyle="black";
pincel.strokeRect(x,y, width, height);
}
function escribirTexto(x , y, texto) {
let pantalla = document.querySelector("canvas");
let pincel = pantalla.getContext("2d");
pincel.font="15px Georgia";
pincel.fillStyle="black";
pincel.fillText(texto, x, y);
}
let serie2009 = [6, 47, 41, 3, 3];
let serie2019 = [81, 9, 3, 3, 4];
let colores = ["yellow","red","green", "blue","orange"];
function dibujarBarra(x, y, serie, colores, texto) {
escribirTexto(x,y-10,texto);
let sumario = 0;
for (let i = 0; i< serie.length; i++){
let height = serie[i];
dibujarRectangulo(x,y + sumario,50,height,colores[i]);
sumario = sumario + height;
}
}
dibujarBarra(50, 50, serie2009, colores, "2009");
dibujarBarra(150, 50, serie2019, colores, "2019");
</script>
</body>
</html>