I am trying to make my graph interactive so I can click on the bars and then do some sort of action. Currently I am just trying to get it to interact properly so I am just trying to get it to console.log() the activePoints variable. But there is a problem in the following line:
var activePoints = barChart.getSegmentsAtEvent(evt);
I get the following error in my console:
Uncaught TypeError: barChart.getSegmentsAtEvent is not a function
Btw I have removed the barChartOption portion of the code to make it easier to read.
function graph(id) {
var barChartCanvas = $("#" + id).get(0).getContext("2d");
var barChart = new Chart(barChartCanvas);
var barChartData = getAreaChartData();
barChartData.datasets[0].fillColor = "#2E2EFE";
barChartData.datasets[0].strokeColor = "#2E2EFE";
barChartData.datasets[0].pointColor = "#2E2EFE";
var barChartOptions = {
};
barChartOptions.datasetFill = false;
barChart.Bar(barChartData, barChartOptions);
$("#"+id).click(
function(evt){
var activePoints = barChart.getSegmentsAtEvent(evt);
console.log("activePoints= ", activePoints);
}
);
}
});
I tried googling the error but could not find a solution for this issue. Is there anyone who can explain to me what I have done wrong?