AngularJS中的Dobut Click事件

时间:2016-02-24 09:54:59

标签: javascript angularjs

我在我的档案中整合了圆环图。我想在甜甜圈的每个切片上都有一个点击事件。我没有得到如何进行点击事件。这是我的代码

<!DOCTYPE html>
<html ng-app="MyApp" >
<head>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="angular-chart.css">
<link rel="stylesheet" href="style.css">
</head>
<body ng-controller="MyCtrl">
<div class="col-sm-6">
<canvas id="doughnut" class="chart chart-doughnut" data="polarData.data" labels="polarData.labels" legend="true">
</canvas> 
</div>
<script>document.write("<base href=\"" + document.location + "\" />");</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-animate.js"></script>
<script type="text/javascript" src="Chart.js"></script>
<script type="text/javascript" src="angular-chart.js"></script>
<script src="app.js"></script>
</body>
</html>

这是我的js文件

var app = angular.module("MyApp", ["ngAnimate", "angular-chart"]);
  app.controller('MyCtrl', function($scope, $timeout) {
             $scope.name = '';    
             $scope.data = {
         singleSelect: null,
             multipleSelect: [],
             option1: 'option-1',
        };
           $scope.forceUnknownOption = function() {
            $scope.data.singleSelect = 'nonsense';
        };

            $scope.polarData = {
            labels: ["January", "February", "March", "April"],
            data: [50, 50, 50, 50],
            };
  });

1 个答案:

答案 0 :(得分:0)

您需要在画布上添加chart-click="onClick"属性。

并将此方法添加到您的控制器

 $scope.onClick = function (points, evt) {
    console.log(points, evt);
  };

以下是详细信息:http://jtblin.github.io/angular-chart.js/#doughnut-chart