I use line of Chart.js( Version: 2.7.2 ) in my application and I open dialog when clicking on some element and I need to get label(date on xAxes) of the current element. Googling I found examples and trying to make as next :
var lineCanvas = document.getElementById("canvasVotesByDays");
var ctx = lineCanvas.getContext('2d');
var lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: monthsXCoordItems,
datasets: [
{
label: 'Correct Votes',
...
lineCanvas.onclick = function (e) {
console.log("INSIDE lineChart::")
console.log(lineChart)
var slice = lineChart.getPointsAtEvent(e);
...
But on the last line I got error :
Uncaught TypeError: lineChart.getPointsAtEvent is not a function
at HTMLCanvasElement.lineCanvas.onclick
In the console I see the propeerties of the lineChart object: https://i.sstatic.net/q8zuJ.jpg
Why error and how to get label property?
Thank you!