vue+element+echarts 制作数据统计饼图

概要

vue+element+echarts:制作数据统计饼图

整体架构流程

1、安装环境:npm install
2、编译调试:npm run dev
3、部署打包:npm run build

主要代码

饼图显示各个数据领域占比

<div class="chart-pie" id="chartPie1">
mounted() {
			//获取页面的echarts图表
			this.chartPie1 = echarts.init(document.getElementById('chartPie1'));
},
this.formPie1(this.dataResult.hangup, 'dataPie1'); //挂断统计
this.chartPie1.setOption(this.dataPie1);
formPie1(dataPie, curveName) {
				let pieWidth = this.chartPie1.getWidth() / 2;
				let colors = ["#00C5D1", "#FFA572", "#D3D6DD"];
				let i = 0;
				this[curveName] = {
					tooltip: {
						trigger: 'item',
						formatter: "{a} <br/>{b}: {c} ({d}%)",
						transitionDuration: 0, //过度默认0.4s效果导致模糊
					},
					legend: {
						textStyle: {
							fontFamily: 'Source Han Sans CN, Source Han Sans CN',
							fontWeight: 400,
							fontSize: 12,
							color: '#6E87AB',
							lineHeight: 20,
							fontStyle: 'normal',
						},
						bottom: 2,
						left: 'center',
						data: ['正常挂断', '中途挂断', '无挂断状态'],
						selectedMode: false,
					},
					backgroundColor: '#fff', // 设置背景色
					series: [{
						name: '挂断统计',
						type: 'pie',
						radius: ['40%', '55%'],
						startAngle: 130, //饼图的起始角度配置
						minAngle: 5, //饼图的最小角度配置
						animationDuration: function(idx) {
							// 越往后的数据时长越大
							return idx * 600;
						},
						animationEasing: '挂断统计',
						animationDuration: 800,
						label: {
							alignTo: 'edge',
							formatter: '{name|{b}:{c}}\n{time|{d}%}',
							minMargin: 50,
							edgeDistance: 60,
							lineHeight: 24,
							rich: {
								time: {
									fontSize: 12,
									color: '#999',
								}
							}
						},
						labelLine: {
							length: 20,
							maxSurfaceAngle: 20
						},
						labelLayout: function(params) {
							const isLeft = params.labelRect.x < pieWidth;
							const points = params.labelLinePoints;
							// Update the end point.
							points[2][0] = isLeft ?
								params.labelRect.x :
								params.labelRect.x + params.labelRect.width;
							console.log("points:", points);
							return {
								labelLinePoints: points
							};
						},
						data: dataPie,
						itemStyle: {
							normal: {
								// 设置饼图的颜色
								color: function() {
									return colors[i++];
								}
							},
							emphasis: {
								shadowBlur: 10,
								shadowOffsetX: 0,
								shadowColor: 'rgba(0, 0, 0, 0.5)'
							}
						}
					}]
				};
			},

小结

通过echarts官网查询参数:
图参数配置

  • 12
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值