Several datasets
Histogram datasets on the same chart draw over each other, in dataset order. Translucent fills let both show. Each dataset keeps its own bins here; to give them the same edges, see Shared bins.
ts
// Two histograms over each other, with translucent fills.
import type {ChartConfiguration} from 'chart.js';
import {classA, classB} from './data/index.js';
const config: ChartConfiguration<'histogram'> = {
type: 'histogram',
data: {
datasets: [
{
label: 'Class A',
data: classA,
binWidth: 5,
binStart: 30,
backgroundColor: 'rgba(54, 162, 235, 0.5)'
},
{
label: 'Class B',
data: classB,
binWidth: 5,
binStart: 30,
backgroundColor: 'rgba(255, 99, 132, 0.5)'
}
]
},
options: {
scales: {
x: {title: {display: true, text: 'Score'}},
y: {title: {display: true, text: 'Students'}}
}
}
};
export default config;