UNPKG

simple-chartjs

Version:

Un module ChartJS simple d'utilisation, rapide et puissant !

46 lines (45 loc) 1.51 kB
module.exports = class Graph { /** * @typedef {object} GraphConfig * @property {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'scatter'} type * @property {string} label * @property {string[] | number[]} values * @property {string} borderColor * @property {string} backgroundColor * @property {boolean} showPoints */ /** * @param {GraphConfig} config */ constructor(config) { this.type = config?.type || undefined; this.label = config?.label || ''; this.data = config?.values || []; this.borderColor = config?.borderColor || ''; this.backgroundColor = config?.backgroundColor || ''; this.showPoints = config.showPoints || false; }; /* RENDERING */ /** * @typedef {object} DataObject * @property {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'scatter'} type * @property {string} label * @property {any[]} data */ /** * @returns {DataObject} */ renderToData() { let response = { type: this.type, label: this.label, data: this.data, borderColor: this.borderColor, backgroundColor: this.backgroundColor }; if(this.showPoints) { response.pointBorderColor = 'rgba(255, 255, 255, 0)'; response.pointBackgroundColor = 'rgba(255, 255, 255, 0)'; }; }; };