1👍
The tooltip for points are provided using the options
binding for canvas.
Add the tooltip as a callback to your scatterChartOptions
object like so in your TS file:
public scatterChartOptions: ChartOptions = {
responsive: true,
tooltips: {
callbacks: {
label: (item, data) =>
{
console.log(item);
return 'Label: ' + item.xLabel + ' ' + item.yLabel
}
}
}
};
This should display a simple label with your x and y values.
Take a look at this working StackBlitz.
- [Chartjs]-ChartJs with try catch
- [Chartjs]-How can I show Bootstrap modal when on click in individual bars in chart.js
0👍
Thanks to Viqas’s tip, I managed to solve this:
tooltips: {
callbacks: {
label: (item, data) =>
{
if (item.index===0){
return 'Risque: 0'
}
else if (item.index===1) {
return 'Risque: 1'
}
}
}
}
This way, I can control what label to display depending on which point I want.
Source:stackexchange.com