highchart饼图Data labels放在连接线的上方

highchart官网api

先上效果图:
饼图

代码;

Highcharts.chart('container', {
	chart: {
		plotBackgroundColor: null,
		plotBorderWidth: null,
		plotShadow: false,
		type: 'pie'
	},
	title: {
		text: '2018年1月浏览器市场份额'
	},
	tooltip: {
		pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	},
	plotOptions: {
		pie: {
			size: '60%',
			allowPointSelect: true,
			cursor: 'pointer',
			dataLabels: {
				enabled: true,
				alignTo: 'toPlotEdges',
				format: '<b>{point.name}</b>: {point.y}',
				y: -14,
				// 重点是这个地方
				connectorShape: function (labelPosition, connectorPosition, options) {
					var
					touchingSliceAt = connectorPosition.touchingSliceAt,
						alignment = labelPosition.alignment,
						left = 0,
						right = 0;
					if (alignment == 'left') {
						left = labelPosition.x + this.dataLabel.bBox.width + 14
						right = labelPosition.x + 2
					} else {
						left = labelPosition.x - this.dataLabel.bBox.width - 14
						right = labelPosition.x - 2
					}
					return ['M',
							left,
							labelPosition.y,
							'L',
							right,
							labelPosition.y,
							'L',
							touchingSliceAt.x,
							touchingSliceAt.y
						   ];
				}
			}
		}
	},
	series: [{
		name: 'Brands',
		colorByPoint: true,
		data: [{
			name: 'Chrome',
			y: 61.41,
			sliced: true,
			selected: true
		}, {
			name: 'Internet Explorer',
			y: 11.84
		}, {
			name: 'Firefox',
			y: 10.85
		}, {
			name: 'Edge',
			y: 4.67
		}, {
			name: 'Safari',
			y: 4.18
		}, {
			name: 'Sogou Explorer',
			y: 1.64
		}, {
			name: 'Opera',
			y: 1.6
		}, {
			name: 'QQ',
			y: 1.2
		}, {
			name: 'Other',
			y: 2.61
		}]
	}]
});
<div id="container" style="min-width:400px;height:400px"></div>

其中比较重要的是:connectorShape 这个配置, 有两种情况,以上是设置成函数方法实现的。另外一种就是直接设置属性(
crookedLine:带转折

		dataLabels: {
			connectorShape: 'crookedLine',
			crookDistance: '70%' // 转折线长度
		}

straight:一条直线

		dataLabels: {
			connectorShape: 'straight'
		}

在这里插入图片描述
官方样例

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值