1👍
✅
You can create your own custom interface by extending the one that is already being used and add the custom option you added to your dataset:
import { Chart, TooltipItem } from 'chart.js';
interface CustomTooltipItem extends TooltipItem<'scatter'> {
raw: {
x: number,
y: number,
name: string,
}
}
const ctx = document.getElementById("myChart") as HTMLCanvasElement;
const myChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: '# of Votes',
data: [{ x: 1, y: 10, name: 'John' }, { x: 2, y: 5, name: 'Linda' }, { x: 3, y: 7, name: 'Erin' }, { x: 4, y: 4, name: 'Chloe' }, { x: 5, y: 8, name: 'Paul' }],
}]
},
options: {
plugins: {
tooltip: {
callbacks: {
label: (context: CustomTooltipItem) => {
return [context.raw.name, `age: ${context.parsed.x} years`, `height change: ${context.parsed.y} in`]
}
}
}
}
}
});
Source:stackexchange.com