我使用chart.js之/角chart.js之显示在饼图一些数据。
我需要的功能,其中,当用户将单击图表派的单击事件将在选定的图表值复制内的标签上。
我能够通过这个动作来触发事件:
$scope.chartClick = function() {
alert('ok');
}
这就是我的标记有:
<canvas id="pie" class="chart chart-pie"
chart-data="data" chart-labels="labels" display="true" chart-click="chartClick()" chart-options="options"></canvas>
任何想法如何,我可以通过一些参数,该事件实际获得的价值?
完全控制:
.controller('InvestorLtvReportController', [
'$scope', '$http', '$state', function ($scope, $http, $state) {
$scope.labels = [];
$scope.data = [];
$scope.options = {
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: 'rgb(255, 99, 132)'
}
}
};
$scope.chartClick = function (points, evt) {
console.log(points, evt);
};
$http({
url: 'http://myapi/api/Manage/GetUserRole',
method: "GET"
}).success(function (data, status) {
$scope.isInvestor = false;
angular.forEach(data, function (value, key) {
if (value == 'Investor') {
$scope.isInvestor = true;
}
});
if (!$scope.isInvestor) {
$state.go('accountlogin');
} else {
$http({
url: 'http://myapi/api/investor/GetInvestorLtvReport',
method: "GET"
}).success(function (data, status) {
angular.forEach(data, function (value, key) {
$scope.labels.push(value.Amortisation);
$scope.data.push(value.PercOfFund);
});
}).error(function (data, status) {
console.log(data);
});
}
})
}
])
你可以这样做,
<canvas id="pie" chart-click="onClick" class="chart chart-pie"chart-data="data" chart-labels="labels"></canvas>
控制器:
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);
};
}]);
如果您仍然需要帮助,对于最新的版本,你得到的标签:
$scope.onClick = function (points, evt) {
console.log(points[0]._view.label);
}
这为我工作,当你点击一个栏上,以获得数据的解决方案是以下
$scope.clickBar = (points, evt, element) => {
if (element != undefined) {
console.log(points,evt,element);
}
};