Files
dashboard-infra/js/charts.js
T
kvilches1410 5467427a08 nuevo dash
2026-03-31 16:57:26 -03:00

48 lines
1.1 KiB
JavaScript

/**
* js/charts.js
* Encargado de instanciar, dibujar y destruir gráficos de Chart.js
*/
const COLORS = [
'#0052cc','#36b37e','#ff5630','#6554c0','#ff8b00',
'#00b8d9','#57d9a3','#f99cdb','#8777d9','#344563',
'#403294','#00875a','#de350b','#505f79','#42526e',
];
export const chartsManager = {
instances: {},
_peopleOrder: [],
personColor(name) {
let idx = this._peopleOrder.indexOf(name);
if (idx < 0) {
this._peopleOrder.push(name);
idx = this._peopleOrder.length - 1;
}
return COLORS[idx % COLORS.length];
},
destroyChart(id) {
if (this.instances[id]) {
this.instances[id].destroy();
delete this.instances[id];
}
},
drawBarChart(id, canvasId, labels, datasets, options = {}) {
this.destroyChart(id);
const ctx = document.getElementById(canvasId);
if (!ctx) return;
this.instances[id] = new Chart(ctx, {
type: 'bar',
data: { labels, datasets },
options: {
responsive: true,
maintainAspectRatio: false,
...options,
}
});
}
};