If you are working with chart js options, make sure to utilize the onClick event feature. You can find more information about it here.
By using onClick, you will be able to access the event and refer to the code snippet below to retrieve the index accordingly.
In addition, the x and y values are also displayed for reference.
I believe the following code snippet should help resolve your concern:
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["2015-01", "2015-02", "2015-03", "2015-04", "2015-05", "2015-06", "2015-07", "2015-08", "2015-09", "2015-10", "2015-11", "2015-12"],
datasets: [{
label: '# of Tomatoes',
data: [12, 19, 3, 5, 2, 3, 20, 3, 5, 6, 2, 1],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
...
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
...
],
borderWidth: 1
}]
},
options: {
responsive: false,
onClick: function(c,i){
e = i[0];
console.log("index",e._index)
var x_value = this.data.labels[e._index];
var y_value = this.data.datasets[0].data[e._index];
console.log("x value",x_value);
console.log("y value",y_value);
},
scales: {
xAxes: [{
ticks: {
maxRotation: 90,
minRotation: 80
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<canvas id="myChart"></canvas>