I am using Angular 4 and Chart js 2.9.4 – bar chart and pie chart where I am hovering on 2nd column and showing me tooltip of 1st column. ![Chart tooltip issue]
(https://i.sstatic.net/YHNenMx7.jpg)
type: 'bar',
data: {
labels: [X,Y,Z],
datasets: [{
label: [''],
data: [
10,
12,
14
],
backgroundColor: [
'red'
'yellow',
'blue'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
layout: {
padding: {
left: 0,
right: 0,
top: 0,
bottom: 0
}
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
display: false,
},
gridLines: {
display: true,
},
},
],
xAxes: [
{
gridLines: {
display: true,
},
},
],
},
legend: {
display: false,
},
tooltips: {
position: 'average',
intersect: false,
callbacks: {
label: function (tooltipItem, data) {
const dataset = data.datasets[tooltipItem.datasetIndex];
const value = dataset.data[tooltipItem.index];
const label = data.labels[tooltipItem.index];
return `${label}: ${value}`;
}
}
},
onClick: function (event) {
const activePoints = this.getElementsAtEventForMode(event, 'nearest', { intersect: true }, true);
if (activePoints.length) {
const firstPoint = activePoints[0];
const label = this.chart.data.labels[firstPoint._index];
const value = this.chart.data.datasets[firstPoint._datasetIndex].data[firstPoint._index];
console.log(`Clicked on ${label}: ${value}`);
}
}
}
I have tried different configuration in tooltips and debugged the code in the chart 2.9.4 library as well but, still it’s not working