Chart.js
Options Configuration
Title, legend, axis formatting, animations, and live updates.
By EZ4Code Team
chartoptionsconfig
Code
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar'],
datasets: [{ label: 'Sales', data: [30, 50, 45] }]
},
options: {
responsive: true,
interaction: { mode: 'index', intersect: false },
plugins: {
title: { display: true, text: 'Sales Report', font: { size: 18 } },
legend: { position: 'top', labels: { boxWidth: 12 } }
},
scales: {
x: { grid: { display: false } },
y: {
beginAtZero: true,
ticks: { callback: v => '$' + v },
grid: { color: 'rgba(0,0,0,0.05)' }
}
},
animation: { duration: 1000, easing: 'easeInOutQuart' }
}
});
// Live update: push new data and re-render
chart.data.labels.push('Apr');
chart.data.datasets[0].data.push(60);
chart.update();
// chart.update('none'); // skip animation
// chart.reset(); // clear animation stateExplanation
options is the central configuration object covering plugins (title, legend), scales (axis formatting via ticks.callback), interaction modes, and animation. interaction.mode='index' shows all dataset values at a hovered x position. Use chart.update() to apply live data changes; pass 'none' to skip the redraw animation.
More Chart.js Snippets
Bar Chart
Vertical bar chart with custom colors and rounded corners.
Line Chart
Smooth line chart with fill, tension, and hover styling.
Pie Chart
Pie chart with per-slice colors and legend positioning.
Doughnut Chart
Doughnut chart with cutout control and centered title.
Radar Chart
Multi-series radar chart for comparing entities across dimensions.
Responsive Chart
Chart that fills its container with maintainAspectRatio disabled.