如何为角度js条形图添加事件

时间:2015-03-18 18:51:11

标签: javascript jquery angularjs

您好我想为角度js条形图添加onclick事件并获取Y轴值。如何实现这一点是我的代码

 <div ng-controller="BarCtrl" class="chart_contr" style="margin-left: auto;margin-right: auto;margin-top: 10%;width: 300px;padding:0px 10px;">
         <canvas id="bar" class="chart chart-bar" data="data" labels="labels" width="400" height="400"></canvas> 
                            </div>

的javascript

 app.controller("BarCtrl", function ($scope) {
  $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
  $scope.series = ['Series A', 'Series B'];

  $scope.data = [
    [65, 59, 80, 81, 56, 55, 40],
    [28, 48, 40, 19, 86, 27, 90]
  ];
  });

2 个答案:

答案 0 :(得分:5)

click="onClick"

中添加ng-click(非<canvas>)属性
<canvas id="bar" class="chart chart-bar" data="data" labels="labels" width="400" height="400" click="onClick"></canvas> 

将此添加到您的控制器:

  $scope.onClick = function (points, evt) {
    console.log(points[0].value); // 0 -> Series A, 1 -> Series B
  };

答案 1 :(得分:0)

你可以在ng-click中访问$ event,这样我认为你应该可以使用getY()