I created a pie chart with chartjs
,
but when I click on a specific slice, the click event is not taken.
View:
<div ng-controller="ProjectsController">
<a>Projects</a>
<br>
</br>
<canvas id="myPieChart" width="600" height="600" ng-click="chartClick()"></canvas>
Controller:
'use strict';
angular.module('Progs')
.controller('ProjectsController', ['$scope', '$rootScope', '$http', '$window', '$state',
function ($scope, $rootScope, $http, $window, $state) {
//...
$scope.chartClick = function (event) {
console.log('chartClick');
//console.log("segment: " + $scope.chart.getSegmentsAtEvent(event));
}
//...
}
What's wrong with my code?
Please note: I am not using angular-chart.js
If you are using
angular-chart
please usechart-click = "chartClick"
.I guess the
chart.js
overrides the click event and doesn't pass it on to angular, so you can't get ang-click
event triggered.You could try binding the click event externally using
angular.element('#myPieChart')
but I am not sure about it.Use html onclick feature and access the scope using any id
Example:
I studied your problem and be reading @MohammadMansoor's answer I tried to implement the solution for you.
here is the plunk for the same implementation