【echarts】3D双柱形图

在这里插入图片描述

const offsetX = 16;
const offsetY = 8;
[-18, 18].forEach((customOffset, index) => {
	const CubeLeft = echarts.graphic.extendShape({
		shape: {
			x: 0,
			y: 0,
		},
		buildPath: function (ctx, shape) {
			const xAxisPoint = shape.xAxisPoint;
			const c0 = [shape.x - customOffset, shape.y];
			const c1 = [shape.x - offsetX - customOffset, shape.y - offsetY];
			const c2 = [xAxisPoint[0] - offsetX - customOffset, xAxisPoint[1] - offsetY];
			const c3 = [xAxisPoint[0] - customOffset, xAxisPoint[1]];
			ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath();
		},
	});
	const CubeRight = echarts.graphic.extendShape({
		shape: {
			x: 0,
			y: 0,
		},
		buildPath: function (ctx, shape) {
			const xAxisPoint = shape.xAxisPoint;
			const c1 = [shape.x - customOffset, shape.y];
			const c2 = [xAxisPoint[0] - customOffset, xAxisPoint[1]];
			const c3 = [xAxisPoint[0] + offsetX - customOffset, xAxisPoint[1] - offsetY];
			const c4 = [shape.x + offsetX - customOffset, shape.y - offsetY];
			ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
		},
	});
	const CubeTop = echarts.graphic.extendShape({
		shape: {
			x: 0,
			y: 0,
		},
		buildPath: function (ctx, shape) {
			const c1 = [shape.x  - customOffset, shape.y];
			const c2 = [shape.x + offsetX - customOffset, shape.y - offsetY];
			const c3 = [shape.x  - customOffset, shape.y - offsetX];
			const c4 = [shape.x - offsetX - customOffset, shape.y - offsetY];
			ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
		},
	});
	echarts.graphic.registerShape('CubeLeft' + index, CubeLeft);
	echarts.graphic.registerShape('CubeRight' + index, CubeRight);
	echarts.graphic.registerShape('CubeTop' + index, CubeTop);
});
const MAX =[ 800, 800, 800, 800, 800, 800, 800];
const NAME = [2015, 2016, 2017, 2018, 2019, 2020, 2021];
const VALUE = [200, 400, 300, 500, 700, 300, 100];
const VALUE2 = [500, 200, 700, 400, 300, 600, 400];
option = {
	backgroundColor: '#012366',
	grid: {
		left: '5%',
		right: 0,
		bottom: '5%',
		top: '5%',
		containLabel: true,
	},
	tooltip: {
		trigger: 'axis',
		axisPointer : {            // 坐标轴指示器,坐标轴触发有效
			type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
		},
		formatter: function(e) {
			var str =
					e[2].axisValue +
					"<br>" +
					"<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
					"rgba(225,155,172, 1)" +
					";'></span>" +
					"课程数量 : " +
					e[2].value +
					"<br>" +
					"<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
					"rgba(25,155,172, 1)" +
					";'></span>" +
					"完成数量 : " +
					e[3].value;
			return str;
		},
	},
	legend: {
		orient: 'vertical',
		x: 'right',
		y: 'center',
		data: ['课程数量', '完成数量', ]
	},
	xAxis: {
		type: 'category',
		data: NAME,
		axisLine: {
			show: true,
			lineStyle: {
				width: 2,
			color: '#7ca7d9',
			},
		},
		axisTick: {
			show: false,
		},
		axisLabel: {
			fontSize: 14,
		},
	},
	yAxis: {
		type: 'value',
		minInterval: 1,
		axisLine: {
			show: true,
			lineStyle: {
				width: 2,
		    	color: '#2B7BD6',
			},
		},
		splitLine: {
			show: true,
			lineStyle: {
				color: 'rgba(201,217,241,0.23)',
			},
		},
		axisTick: {
			show: false,
		},
		axisLabel: {
			fontSize: 14,
		},
	},
	
 dataZoom: [{
    show: true,
    height: 30,
    xAxisIndex: [
        0
    ],
    bottom: 30,
    start: 10,
    end: 50,
    handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
    handleSize: '110%',
    handleStyle:{
        color:"#d3dee5",
        
    },
       textStyle:{
        color:"#fff"},
       borderColor:"#90979c"
    
    
}, {
    type: "inside",
    show: true,
    height: 15,
    start: 1,
    end: 10
}],
	series: [
		{
			// 最大高度
			type: 'custom',
			renderItem: function(params, api) {
				const location = api.coord([api.value(0), api.value(1)])
				return {
					type: 'group',
					children: [{
						type: 'CubeLeft0',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(25,155,172, .1)`
						}
					}, {
						type: 'CubeRight0',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(25,155,172, .3)`
						}
					}, {
						type: 'CubeTop0',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(25,155,172, .4)`
						}
					}]
				}
			},
			data: MAX
		} ,

		{
			// 最大高度
			type: 'custom',
			renderItem: function(params, api) {
				const location = api.coord([api.value(0), api.value(1)])
				return {
					type: 'group',
					children: [{
						type: 'CubeLeft1',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(225,155,172, .1)`
						}
					}, {
						type: 'CubeRight1',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(225,155,172, .3)`
						}
					}, {
						type: 'CubeTop1',
						shape: {
							api,
							x: location[0],
							y: location[1],
							xAxisPoint: api.coord([api.value(0), 0])
						},
						style: {
							fill: `rgba(225,155,172, .4)`
						}
					}]
				}
			},
			data: MAX
		} ,
		{
			type: 'custom',

			renderItem: (params, api) => {
				const location = api.coord([api.value(0), api.value(1)]);
				return {
					type: 'group',
					children: [
						{
							type: 'CubeLeft0',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(25,155,172, .5)',
									},
									{
										offset: 1,
										color: 'rgba(25,155,172, .5)',
									},
								]),
							},
						},
						{
							type: 'CubeRight0',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(25,155,172, 1)',
									},
									{
										offset: 1,
										color: 'rgba(25,155,172, .5)',
									},
								]),
							},
						},
						{
							type: 'CubeTop0',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(25,155,172, .8)',
									},
									{
										offset: 1,
										color: 'rgba(25,155,172, .8)',
									},
								]),
							},
						},
					],
				};
			},
			data: VALUE,
		},
		{
			type: 'custom',
			renderItem: (params, api) => {
				const location = api.coord([api.value(0), api.value(1)]);
				return {
					type: 'group',
					children: [
						{
							type: 'CubeLeft1',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(225,155,172, .5)',
									},
									{
										offset: 1,
										color: 'rgba(225,155,172, .5)',
									},
								]),
							},
						},
						{
							type: 'CubeRight1',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(225,155,172, 1)',
									},
									{
										offset: 1,
										color: 'rgba(225,155,172, .5)',
									},
								]),
							},
						},
						{
							type: 'CubeTop1',
							shape: {
								api,
								xValue: api.value(0),
								yValue: api.value(1),
								x: location[0] - 0,
								y: location[1],
								xAxisPoint: api.coord([api.value(0), 0]),
							},
							style: {
								fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
									{
										offset: 0,
										color: 'rgba(225,155,172, .8)',
									},
									{
										offset: 1,
										color: 'rgba(225,155,172, .8)',
									},
								]),
							},
						},
					],
				};
			},
			data: VALUE2,
		},
	],
};
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值