[Chartjs]-Chart.js chart-click pass parameter in Angular controller

3๐Ÿ‘

โœ…

You can do this,

<canvas id="pie" chart-click="onClick" class="chart chart-pie"chart-data="data" chart-labels="labels"></canvas> 

Controller:

app.controller('AppCtrl', ['$scope', function($scope){
  $scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
  $scope.data = [300, 500, 100];
   $scope.onClick = function (points, evt) {
    console.log(points, evt);
  };
}]); 

DEMO

2๐Ÿ‘

A solution that worked for me to get the data when you click on a bar is the following

$scope.clickBar = (points, evt, element) => {
    if (element != undefined) {
        console.log(points,evt,element);
    }
};

1๐Ÿ‘

If you still need help with that, for the recent version, you get the label with:

$scope.onClick = function (points, evt) {
    console.log(points[0]._view.label);
}

Leave a comment