Chart.js v2.6: Add arrows to pie chart output values(Chart.js v2.6:为饼图输出值添加箭头)
问题描述
我正在使用 Chart.js v2.6 输出饼图.数据来自 MySQL 数据库.图表正确呈现,但我需要为数据值添加箭头,如下面的屏幕截图所示.
I am using Chart.js v2.6 to output a pie chart. The data is obtained from MySQL database. The chart renders properly, but I need to add arrows to data values as shown in the screenshot below.
带箭头的饼图示例:
下面是我使用 Chart.js 输出饼图的代码:
Below is my code to output pie chart using Chart.js:
var chartdata_order_status = {
labels: status,
datasets: [{
label: 'Order status',
backgroundColor: ["#00b0f0","#92d050","#ffc000","#ff6dd9"],
data: count_status
}]
};
var pieGraph = new Chart(ctx3, {
type: 'pie',
data: chartdata_country_orders,
options: {
pieceLabel: {
mode: 'value',
position: 'outside',
fontColor: '#000',
format: function (value) {
return '$' + value;
}
},
title: {
display: true,
text: 'Total Sales by Country - Top 5',
fontSize: 15,
fontStyle: 'bold'
},
legend: {
display: true,
position: 'bottom',
},
}
});
我没有包含用于从 MySQLtable 获取数据的 PHP 代码.
I have not included the PHP code for obtaining data from the MySQLtable.
推荐答案
您现在可以使用 Chart.PieceLabel.js
并获取 slices.s 之外的标签,
You can now use Chart.PieceLabel.js
and get labels outside the slices.s,
演示
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];
$scope.options = {
pieceLabel: {
render: 'label',
fontColor: '#000',
position: 'outside',
segment: true
}
};
});
<script src="aHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvQ2hhcnQuanMvMi4yLjEvQ2hhcnQuanM="></script>
<script src="aHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvYW5ndWxhci5qcy8xLjUuOC9hbmd1bGFyLmpz"></script>
<script src="aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L2FuZ3VsYXIuY2hhcnRqcy9sYXRlc3QvYW5ndWxhci1jaGFydC5qcw=="></script>
<script src="aHR0cHM6Ly9yYXdnaXQuY29tL2JlYXZlcjcxL0NoYXJ0LlBpZWNlTGFiZWwuanMvbWFzdGVyL2J1aWxkL0NoYXJ0LlBpZWNlTGFiZWwubWluLmpz"></script>
<div ng-app="app" ng-controller="ChartCtrl">
<canvas id="pie" class="chart chart-pie"
chart-data="data" chart-labels="labels" chart-options="options">
</canvas>
</div>
这篇关于Chart.js v2.6:为饼图输出值添加箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chart.js v2.6:为饼图输出值添加箭头
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01