Values from another dataset
source bins the values of another dataset, named by index or by id. Here a hidden line of sensor readings feeds the histogram; click "Readings" in the legend to show it.
ts
// A histogram of another dataset's values, here a hidden line.
import type {ChartConfiguration} from 'chart.js';
import {readings} from './data/index.js';
const config: ChartConfiguration<'histogram' | 'line'> = {
type: 'histogram',
data: {
datasets: [
{
label: 'Temperature distribution',
// No data of its own: the values come from the dataset with id 'readings'.
data: [],
source: 'readings',
binWidth: 0.5
},
{
type: 'line',
id: 'readings',
label: 'Readings',
data: readings,
// The source may be hidden; it still feeds the histogram.
hidden: true
}
]
},
options: {
scales: {
x: {title: {display: true, text: 'Temperature (°C)'}},
y: {title: {display: true, text: 'Readings'}}
}
}
};
export default config;