我正在使用angular-chart.js
library中的极坐标图表。但我的极地图表需要如下所示:
我如何才能达到这个要求?有人以前做过吗?
目前我只是使用来自源代码的代码:
angular.module("app", ["chart.js"]).controller("PolarAreaCtrl", function ($scope) {
$scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales", "Tele Sales", "Corporate Sales"];
$scope.data = [300, 500, 100, 40, 120];
});
和我的观点:
<canvas id="polar-area" class="chart chart-polar-area"
chart-data="data" chart-labels="labels" chart-options="options">
</canvas>
答案 0 :(得分:3)
使用此扩展程序还有另一种选择:
这是一个小提琴:https://jsfiddle.net/beaver71/39293jes/
或SO中的摘录:
angular.module("app", ["chart.js"]).controller("ChartCtrl", function($scope) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.data = [65, 59, 80, 81, 56, 55, 40];
var sum = $scope.data.reduce(function add(a, b) {
return a + b;
}, 0);
$scope.options = {
pieceLabel: {
render: function (args) {
return args.label + " " + Math.round(args.value*100/sum,2)+"%";
},
fontColor: '#000',
position: 'outside',
segment: true
}
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.js"></script>
<script src="https://rawgit.com/beaver71/Chart.PieceLabel.js/master/build/Chart.PieceLabel.min.js"></script>
<div ng-app="app" ng-controller="ChartCtrl">
<canvas id="pie" class="chart chart-polar-area"
chart-data="data" chart-labels="labels" chart-options="options">
</canvas>
</div>
答案 1 :(得分:2)