Skip to main content Accueil Créateurs johnnuwan eva_core chart-js
chart-js Chart.js : bibliothèque JavaScript de graphiques responsives en Canvas — barres, lignes, radar, doughnut, scatter, bubble, mixed, animations, plugins (labels, zoom, annotation).
Aller à l'installation Skills Marketplace Découvrez et explorez les compétences IA créées par la communauté.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Copier le promptAfficher les détails du prompt Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
npx skills add https://github.com/JohnNuwan/EVA_CORE --skill chart-jsLa commande reste sur une seule ligne. Faites défiler horizontalement pour la vérifier avant de la copier.
Vous préférez une copie locale ? Téléchargez les fichiers actuellement disponibles dans SkillsMP.
Télécharger Zip Téléchargement... Métiers associés SOC
Basé sur la classification professionnelle SOC
name chart-js description Chart.js : bibliothèque JavaScript de graphiques responsives en Canvas — barres, lignes, radar, doughnut, scatter, bubble, mixed, animations, plugins (labels, zoom, annotation). version 1.0.0 author EVA license Privée EVA platforms ["linux","macos","windows"] metadata {"EVA":{"tags":["chart.js","chartjs","dataviz","javascript","canvas","charts","responsive"],"homepage":"https://www.chartjs.org/","related_skills":["d3-js","plotly","dashboard-design"]}} prerequisites {"commands":["node","npm"],"npm_packages":["chart.js","chartjs-plugin-datalabels","chartjs-plugin-zoom"]}
Compétence Chart.js — Graphiques Canvas Responsives
Vue d'ensemble
Chart.js est la bibliothèque de graphiques en Canvas la plus populaire pour le web. Elle transforme des données en 8 types de graphiques prêts à l'emploi, responsives, animés et interactifs en une dizaine de lignes de JavaScript. Basée sur HTML5 Canvas, elle offre des performances élevées même avec des milliers de points.
Philosophie : "Un graphique parfait en 5 lignes, personnalisable à l'infini."
Quand Chart.js plutôt que D3 ? Chart.js est le bon choix quand on veut des graphiques standards (barres, lignes, radar) rapidement, sans re-inventer chaque pixel. D3 est nécessaire quand on a besoin d'un contrôle total (layouts custom, géo, force graphs).
Quand l'utiliser
Activez cette compétence lorsque l'utilisateur :
Veut intégrer un graphique rapidement dans une page web.
A besoin de graphiques responsives (redimensionnement automatique).
Souhaite des animations fluides sans configuration complexe.
Veut un export en PNG/JPEG natif.
A besoin de plugins : datalabels, zoom, annotation, crosshair.
Prérequis
npm install chart.js
1. Configuration de Base
1.1 Premier Graphique
<canvas id ="myChart" width ="400" height ="400" > </canvas >
import { Chart , registerables } from 'chart.js' ;
Chart .register (...registerables);
const ctx = document .getElementById ('myChart' ).getContext ('2d' );
new Chart (ctx, {
type : ,
: {
: [ , , , , , ],
: [{
: ,
: [ , , , , , ],
: ,
: ,
}]
},
: {
: ,
: ,
: {
: {
: ,
:
},
: {
:
}
}
}
});
'line'
data
labels
'Jan'
'Fév'
'Mar'
'Avr'
'Mai'
'Juin'
datasets
label
'Ventes 2024'
data
12
19
15
25
22
30
borderColor
'rgb(75, 192, 192)'
tension
0.3
options
responsive
true
maintainAspectRatio
false
plugins
title
display
true
text
'Ventes Mensuelles 2024'
legend
position
'bottom'
1.2 Types de Graphiques Disponibles Type Constructeur Usage lineline / scatter Tendances, séries temporelles barbar / horizontalBar Comparaisons catégorielles radarradar Profils multidimensionnels doughnutdoughnut Proportions (trou central) piepie Proportions polarAreapolarArea Proportions radiales bubblebubble Corrélations tri-dimensionnelles scatterscatter Nuages de points mixedCombinaison Plusieurs types sur le même canvas
2. Types de Graphiques Détaillés
2.1 Bar Chart (Vertical & Horizontal) new Chart (ctx, {
type : 'bar' ,
data : {
labels : ['Produit A' , 'Produit B' , 'Produit C' , 'Produit D' ],
datasets : [
{
label : 'Ventes' ,
data : [65 , 59 , 80 , 81 ],
backgroundColor : [
'rgba(255, 99, 132, 0.7)' ,
'rgba(54, 162, 235, 0.7)' ,
'rgba(255, 206, 86, 0.7)' ,
'rgba(75, 192, 192, 0.7)' ,
],
borderWidth : 2 ,
},
{
label : 'Objectif' ,
data : [70 , 70 , 70 , 70 ],
type : 'line' ,
borderColor : 'rgb(255, 99, 132)' ,
borderDash : [5 , 5 ],
pointRadius : 0 ,
}
]
},
options : {
indexAxis : 'y' ,
scales : {
x : { stacked : false },
y : { stacked : false },
}
}
});
2.2 Line Chart (Série Temporelle) new Chart (ctx, {
type : 'line' ,
data : {
labels : ['2024-01' , '2024-02' , '2024-03' , '2024-04' , '2024-05' ],
datasets : [
{
label : 'Revenus' ,
data : [3000 , 4500 , 3800 , 5200 , 6100 ],
borderColor : '#36a2eb' ,
backgroundColor : 'rgba(54, 162, 235, 0.1)' ,
fill : true ,
tension : 0.4 ,
pointRadius : 4 ,
pointHoverRadius : 6 ,
},
{
label : 'Dépenses' ,
data : [2500 , 2800 , 3000 , 3100 , 3300 ],
borderColor : '#ff6384' ,
backgroundColor : 'rgba(255, 99, 132, 0.1)' ,
fill : true ,
tension : 0.4 ,
pointRadius : 4 ,
}
]
},
options : {
interaction : {
mode : 'index' ,
intersect : false ,
},
plugins : {
tooltip : {
callbacks : {
label : (ctx ) => `${ctx.dataset.label} : ${ctx.parsed.y} €` ,
}
}
}
}
});
2.3 Doughnut / Pie new Chart (ctx, {
type : 'doughnut' ,
data : {
labels : ['Facebook' , 'Google' , 'Direct' , 'Email' , 'Autres' ],
datasets : [{
data : [35 , 25 , 20 , 12 , 8 ],
backgroundColor : [
'#4267B2' , '#4285F4' , '#34A853' , '#EA4335' , '#ccc'
],
borderWidth : 2 ,
cutout : '70%' ,
}]
},
options : {
plugins : {
legend : { position : 'right' },
title : {
display : true ,
text : 'Trafic par Source'
}
}
}
});
2.4 Scatter & Bubble
new Chart (ctx, {
type : 'scatter' ,
data : {
datasets : [{
label : 'Clients' ,
data : [
{ x : 25 , y : 30000 },
{ x : 35 , y : 45000 },
{ x : 45 , y : 55000 },
{ x : 55 , y : 42000 },
],
backgroundColor : 'rgba(54, 162, 235, 0.6)' ,
}]
},
options : {
scales : {
x : {
title : { display : true , text : 'Âge' }
},
y : {
title : { display : true , text : 'Revenu (€)' }
}
}
}
});
new Chart (ctx, {
type : 'bubble' ,
data : {
datasets : [{
label : 'Produits' ,
data : [
{ x : 20 , y : 30 , r : 15 },
{ x : 40 , y : 10 , r : 10 },
{ x : 30 , y : 50 , r : 25 },
{ x : 10 , y : 20 , r : 8 },
],
backgroundColor : 'rgba(255, 99, 132, 0.6)' ,
}]
}
});
2.5 Radar (Profils Multi-Dimensions) new Chart (ctx, {
type : 'radar' ,
data : {
labels : ['Vitesse' , 'Précision' , 'Robustesse' , 'UX' , 'Coût' , 'Scalabilité' ],
datasets : [
{
label : 'Produit A' ,
data : [85 , 70 , 90 , 75 , 60 , 80 ],
borderColor : '#36a2eb' ,
backgroundColor : 'rgba(54, 162, 235, 0.2)' ,
pointBackgroundColor : '#36a2eb' ,
},
{
label : 'Produit B' ,
data : [70 , 90 , 65 , 85 , 80 , 60 ],
borderColor : '#ff6384' ,
backgroundColor : 'rgba(255, 99, 132, 0.2)' ,
pointBackgroundColor : '#ff6384' ,
}
]
},
options : {
scales : {
r : {
beginAtZero : true ,
max : 100 ,
ticks : { stepSize : 20 }
}
}
}
});
3. Options Avancées
3.1 Échelles et Axes options : {
scales : {
x : {
type : 'time' ,
time : {
unit : 'month' ,
displayFormats : { month : 'MMM yyyy' }
},
title : { display : true , text : 'Date' },
grid : { display : false },
ticks : {
maxRotation : 45 ,
maxTicksLimit : 12 ,
}
},
y : {
type : 'linear' ,
beginAtZero : true ,
title : { display : true , text : 'Valeur (€)' },
grid : { color : 'rgba(0,0,0,0.05)' },
ticks : {
callback : (value ) => `${value} €` ,
stepSize : 1000 ,
}
},
y1 : {
type : 'linear' ,
position : 'right' ,
grid : { drawOnChartArea : false },
title : { display : true , text : 'Pourcentage (%)' },
}
}
}
3.2 Animations options : {
animation : {
duration : 1500 ,
easing : 'easeOutQuart' ,
},
animations : {
colors : {
duration : 800 ,
type : 'color' ,
},
y : {
duration : 1000 ,
from : (ctx ) => ctx.chart .scales .y .getPixelForValue (0 ),
}
},
transitions : {
active : { animation : { duration : 200 } },
resize : { animation : { duration : 0 } },
}
}
3.3 Plugins import ChartDataLabels from 'chartjs-plugin-datalabels' ;
import zoomPlugin from 'chartjs-plugin-zoom' ;
import annotationPlugin from 'chartjs-plugin-annotation' ;
Chart .register (ChartDataLabels , zoomPlugin, annotationPlugin);
options : {
plugins : {
datalabels : {
anchor : 'end' ,
align : 'end' ,
color : '#444' ,
font : { weight : 'bold' , size : 11 },
formatter : (value ) => value + '€' ,
},
zoom : {
pan : { enabled : true , mode : 'xy' },
zoom : {
wheel : { enabled : true , modifierKey : 'ctrl' },
pinch : { enabled : true },
drag : { enabled : true , mode : 'x' },
mode : 'x' ,
},
limits : {
x : { minRange : 1000 * 60 * 60 * 24 },
}
},
annotation : {
annotations : {
line1 : {
type : 'line' ,
xMin : '2024-06' ,
xMax : '2024-06' ,
borderColor : 'red' ,
borderWidth : 2 ,
borderDash : [6 , 3 ],
label : {
display : true ,
content : 'Événement' ,
position : 'start' ,
}
},
box1 : {
type : 'box' ,
xMin : '2024-03' ,
xMax : '2024-05' ,
backgroundColor : 'rgba(255, 99, 132, 0.1)' ,
borderWidth : 0 ,
}
}
},
legend : {
position : 'top' ,
labels : {
usePointStyle : true ,
padding : 20 ,
font : { size : 12 },
},
onClick : (e, legendItem, legend ) => {
const index = legendItem.datasetIndex ;
}
},
tooltip : {
enabled : true ,
mode : 'index' ,
intersect : false ,
backgroundColor : 'rgba(0,0,0,0.8)' ,
titleFont : { size : 14 },
bodyFont : { size : 12 },
padding : 12 ,
cornerRadius : 4 ,
callbacks : {
title : (items ) => `Période : ${items[0 ].label} ` ,
label : (item ) => `${item.dataset.label} : ${item.parsed.y} unités` ,
afterLabel : (item ) => `---\nTendance: ${item.parsed.y > 50 ? '↑' : '↓' } ` ,
}
},
}
}
4. Graphiques Mixtes (Mixed) new Chart (ctx, {
type : 'bar' ,
data : {
labels : ['Jan' , 'Fév' , 'Mar' , 'Avr' ],
datasets : [
{
label : 'Revenus' ,
data : [3000 , 4500 , 3800 , 5200 ],
backgroundColor : 'rgba(54, 162, 235, 0.7)' ,
order : 2 ,
},
{
label : 'Marge (%)' ,
data : [30 , 35 , 32 , 38 ],
type : 'line' ,
borderColor : '#ff6384' ,
backgroundColor : 'rgba(255, 99, 132, 0.1)' ,
fill : true ,
yAxisID : 'y1' ,
order : 1 ,
}
]
},
options : {
scales : {
y : {
beginAtZero : true ,
position : 'left' ,
title : { display : true , text : 'Revenus (€)' },
},
y1 : {
beginAtZero : true ,
position : 'right' ,
title : { display : true , text : 'Marge (%)' },
grid : { drawOnChartArea : false },
ticks : { callback : (v ) => `${v} %` },
}
}
}
});
5. Performance et Grands Volumes
options : {
elements : {
point : {
radius : 0 ,
hitRadius : 5 ,
hoverRadius : 3 ,
},
line : {
borderWidth : 1 ,
tension : 0 ,
}
},
animation : {
duration : 0 ,
},
parsing : false ,
normalized : true ,
datasets : {
}
}
new Chart (ctx, {
data : {
labels : [],
datasets : [{
data : [],
}]
},
options : { parsing : false }
});
6. Export (Image/PDF)
document .getElementById ('downloadBtn' ).addEventListener ('click' , () => {
const link = document .createElement ('a' );
link.download = 'graphique.png' ;
link.href = myChart.toBase64Image ('image/png' , 1 );
link.click ();
});
const jpegUrl = myChart.toBase64Image ('image/jpeg' , 0.8 );
import jsPDF from 'jspdf' ;
const pdf = new jsPDF ();
pdf.addImage (myChart.toBase64Image (), 'PNG' , 10 , 10 , 190 , 100 );
pdf.save ('graphique.pdf' );
Pièges Courants (Pitfalls)
Canvas qui se dédouble ou rend mal.
Erreur : Le <canvas> a une taille CSS différente de ses attributs width/height.
Correction : Utiliser responsive: true et ne PAS fixer de width/height fixes en CSS. Chart.js gère le ratio.
Données qui ne s'affichent pas.
Erreur : Les données contiennent des undefined ou null — Chart.js les ignore silencieusement.
Correction : Filtrer avant : data.filter(d => d !== null && d !== undefined).
Graphique qui saute au resize.
Erreur : maintainAspectRatio: false sans conteneur parent dimensionné.
Correction : Mettre le canvas dans un conteneur avec hauteur fixe : <div style="height: 400px"><canvas></canvas></div>.
Plugin qui ne fonctionne pas.
Erreur : Import du plugin sans l'enregistrer avec Chart.register().
Correction : Chart.register(monPlugin) avant d'instancier le graphique.
Lenteur avec beaucoup de datasets.
Erreur : 20+ datasets avec 10 000 points chacun.
Correction : Activer parsing: false, désactiver animations, réduire le nombre de datasets ou regrouper par agrégation.
Dates non reconnues sur l'axe X.
Erreur : L'échelle time nécessite un adaptateur de dates.
Correction : Installer et importer chartjs-adapter-date-fns ou chartjs-adapter-luxon.
Ressources
Checklist