-
-
Save parzibyte/4a0e0d2e42b011bff250cb39c6e94027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Obtener una referencia al elemento canvas del DOM | |
const $grafica = document.querySelector("#grafica"); | |
// Las etiquetas son las que van en el eje X. | |
const etiquetas = ["Enero", "Febrero", "Marzo", "Abril"] | |
// Podemos tener varios conjuntos de datos | |
const datosVentas2020 = { | |
label: "Ventas por mes - 2020", | |
data: [5000, 1500, 8000, 5102], // La data es un arreglo que debe tener la misma cantidad de valores que la cantidad de etiquetas | |
backgroundColor: 'rgba(54, 162, 235, 0.2)', // Color de fondo | |
borderColor: 'rgba(54, 162, 235, 1)', // Color del borde | |
borderWidth: 1,// Ancho del borde | |
}; | |
const datosVentas2021 = { | |
label: "Ventas por mes - 2021", | |
data: [10000, 1700, 5000, 5989], // La data es un arreglo que debe tener la misma cantidad de valores que la cantidad de etiquetas | |
backgroundColor: 'rgba(255, 159, 64, 0.2)',// Color de fondo | |
borderColor: 'rgba(255, 159, 64, 1)',// Color del borde | |
borderWidth: 1,// Ancho del borde | |
}; | |
new Chart($grafica, { | |
type: 'line',// Tipo de gráfica | |
data: { | |
labels: etiquetas, | |
datasets: [ | |
datosVentas2020, | |
datosVentas2021, | |
// Aquí más datos... | |
] | |
}, | |
options: { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero: true | |
} | |
}], | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment