Chart.js Datasets and Options
What you'll learn: How to configure datasets, colors, labels, legends, and tooltips to transform basic Chart.js charts into polished, informative visualizations.
The Core Idea
Think of a Chart.js chart as a canvas painting: the dataset is your subject matter (the actual data), while options are your artistic choices (colors, style, composition). Every Chart.js visualization needs at least one dataset—an object describing what to plot—and benefits from an options configuration that controls how everything looks and behaves.
The Dataset Object
Each dataset is an object within the data.datasets array. At minimum, you provide the data values, but you can also specify:
datasets: [{
label: 'Monthly Sales',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 2,
pointBackgroundColor: 'rgba(255, 99, 132, 1)'
}]
Colors can be single values or arrays (one per data point). The label appears in legends and tooltips.
Global Options
The options object controls chart-wide behavior—legends, tooltips, axes, responsiveness:
options: {
responsive: true,
plugins: {
legend: {
display: true,
position: 'top'
},
tooltip: {
enabled: true,
mode: 'index',
backgroundColor: 'rgba(0, 0, 0, 0.8)'
}
},
scales: {
y: {
beginAtZero: true
}
}
}
Plugins control legends and tooltips. Scales configure axes. The mode: 'index' tooltip setting shows all dataset values at one x-position—perfect for comparing multiple lines.
Key Takeaway: Chart.js separates data concerns (datasets) from presentation concerns (options), giving you fine-grained control over colors, labels, legends, tooltips, and interactive behaviors through clear configuration objects.