Echarts堆叠柱状图显示百分比

Echarts堆叠柱状图显示百分比

效果图

在这里插入图片描述

js代码


//各行业企业分布情况
function showBar1 (x,data) {


	var chart = echarts.init(document.getElementById('bar2'))
	chart.setOption(
		{
			tooltip: {
				trigger: 'axis',
				axisPointer: {            // 坐标轴指示器,坐标轴触发有效
					type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
						
				},
				formatter:function(datas){
					var res = datas[0].name + '<br/>', val;
					let percent = '';
					if(datas[0].value=='0'){
						percent = 0;
					}
					else{
						percent = ((datas[1].value / datas[0].value) * 100).toFixed(2);
					}
					let dotColor0 = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + datas[0].color + '"></span>'
					let dotColor1 = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + datas[1].color + '"></span>'

					res += dotColor0 + datas[0].seriesName  + ": " + datas[0].value  + '</br>';
					res += dotColor1 + datas[1].seriesName  + ": " + datas[1].value  + '</br>';
					res += '覆盖率: '  + percent + '%' + '</br>'
					return res; 

				}
			},
			legend: {
				data: ['企业数', '安责险企业数'],
				textStyle: {
					color: '#97B8C9',
					fontSize: 16

				},
				left: '50%',
				top: '10%',

			},
			grid: {
				top: '30%',
				left: '3%',
				right: '5%',
				bottom: '15%',
				containLabel: true
			},
			dataZoom: [
				{
					show: true,
					bottom: '4%',
					start: 0,
					end: 70,
					height: 20,
					backgroundColor: 'rgba(9,75,127,0.2)',
					fillerColor: '#094B7F',
					borderColor: '#094B80',
					textStyle: {
						color: '#97B8C9'
					}
				}

			],
			xAxis: [
				{
					type: 'category',
					data: x,
					splitLine: {
						lineStyle: {
							color: '#07274D'
						}
					},
					axisLine: {
						lineStyle: {
							color: '#07274D'
						}
					},
					axisTick: {
						lineStyle: {
							color: '#1178C9'
						}
					},
					axisLabel: {
						interval: 0,
						textStyle: {
							color: '#97B8C9',
							fontSize: 14
						},
						formatter: function (v) {
							if (v.length > 5) {
								return v.substring(0, 5) + '...';
							}
							return v;

						}
					}
				}
			],
			yAxis: [
				{
					type: 'value',
					axisLabel: {
						textStyle: {
							color: '#97B8C9',
							fontSize: 16
						}
					},
					axisLine: {
						show: true,
						lineStyle: {
							color: '#07274D'
						}
					},
					axisTick: {
						lineStyle: {
							color: '#1178C9'
						}
					},
					splitLine: {
						show: false
					}
				}
			],
			series: [
				{
					name: '企业数',
					type: 'bar',
					 barGap: '-100%', // Make series be overlap
					// barWidth: '50%',
					yAxisIndex: 0,
					data: data.entNum,
					itemStyle: {
						normal: {
							color: '#199ed8'
						}
					},
					label: {
						normal: {
							show: true,
							position: 'top',
							fontSize: 16
						}
					},barWidth : 35
				},
				{
					name: '安责险企业数',
					type: 'bar',
					yAxisIndex: 0,
					data: data.entBxNum,
					itemStyle: {
						normal: {
							color: '#008000'
						}
					},
					label: {
						normal: {
							show: true,
							position: 'top',
							fontSize: 16
						}
					},barWidth : 35
				}

			]

		}
	)
	$(window).resize(function () {
			chart.resize()
		}
	)
	return chart

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值