let x = ['test1', 'test2', 'test3', 'test4', 'test5']; let y = [10, 20, 30, 40, 50,]; const wid = 20; const w1 = Math.sin(Math.PI / 6) * wid; //4 const w2 = Math.sin(Math.PI / 3) * wid; // 6.8 const snapHeight = wid / 2; const CubeLeft = echarts.graphic.extendShape({ shape: { x: 0, y: 0 }, buildPath: function (ctx, shape) { // 会canvas的应该都能看得懂,shape是从custom传入的 const xAxisPoint = shape.xAxisPoint const c0 = [shape.x, shape.y] const c1 = [shape.x - w2, shape.y] const c2 = [shape.x - w2, xAxisPoint[1]] const c3 = [shape.x, 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, shape.y] const c2 = [shape.x, xAxisPoint[1]] const c3 = [shape.x + w1, xAxisPoint[1] - w2 + snapHeight] const c4 = [shape.x + w1, shape.y - w2 + snapHeight] 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, shape.y] const c2 = [shape.x + w1, shape.y - w2 + snapHeight] //右点 const c3 = [shape.x - w2 + w1, shape.y - w2 + snapHeight] const c4 = [shape.x - w2, shape.y] 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', CubeLeft) echarts.graphic.registerShape('CubeRight', CubeRight) echarts.graphic.registerShape('CubeTop', CubeTop) option = { //你的代码 backgroundColor: 'rgba(0,0,0,.8)', tooltip: { show: false, trigger: 'axis', axisPointer: { type: 'shadow' }, }, grid: { left: '5%', right: '5%', top: '15%', bottom: '10%', containLabel: true }, xAxis: { type: 'category', data: x, axisLine: { show: true, lineStyle: { color: '#fff', width: 1 } }, axisTick: { show: false, length: 9, alignWithLabel: true, lineStyle: { color: '#fff' } }, axisLine: { show: true, lineStyle: { color: '#565f6a', width: 1 } }, axisLabel: { color: '#fff', interval: 0, }, splitLine: { show: false, lineStyle: { color: '#ffffff', } }, }, yAxis: [ { name: '万千瓦时', nameTextStyle: { color: "#fff", fontSize: 20, }, type: 'value', axisLine: { show: true, lineStyle: { color: '#565f6a', width: 1 } }, axiosTick: { show: false }, axisLabel: { show: true, fontSize: 20, color: "#fff", margin: 10, }, splitLine: { show: true, lineStyle: { color: 'rgba(5, 80, 123, .1)', type: 'dashed', width: 1 } }, }, { type: "value", name: "%", min: 0, max: 100, nameTextStyle: { color: "#fff", fontSize: 20, padding: [0, 0, 10, 30], }, axisLine: { show: true, lineStyle: { color: "#84929f", }, }, // splitNumber: 5, splitLine: { show: true, lineStyle: { type: "dashed", width: 1, // 使用深浅的间隔色 color: ["#566471", "#566471"], }, }, axisLabel: { show: true, fontSize: 20, color: "#fff", margin: 10, }, }, ], series: [ { name: "同比", type: "line", yAxisIndex: 1, //使用的 y 轴的 index,在单个图表实例中存在多个 y轴的时候有用 smooth: true, //平滑曲线显示 symbol: "circle", //标记的图形为实心圆 symbolSize: 0, //标记的大小 itemStyle: { // normal: { color: "rgba(253,246,70,1)", borderColor: "rgba(253,246,70,1)", //圆点透明 边框 borderWidth: 0, lineStyle: { color: "rgba(253,246,70,1)", }, }, areaStyle: { color: new echarts.graphic.LinearGradient( 0, 0, 0, 1, [ { offset: 0, color: "rgba(253,246,70,0.3)", }, { offset: 0.6, color: "rgba(253,246,70, 0)", }, ], false ), shadowColor: "rgba(253,246,70, 0.9)", // shadowBlur: 20, }, data: y, }, { name: "环比", type: "line", yAxisIndex: 1, //使用的 y 轴的 index,在单个图表实例中存在多个 y轴的时候有用 smooth: true, //平滑曲线显示 symbol: "circle", //标记的图形为实心圆 symbolSize: 0, //标记的大小 itemStyle: { // normal: { color: "rgba(255,135,6,1)", borderColor: "rgba(255,135,6,1)", //圆点透明 边框 borderWidth: 0, lineStyle: { color: "rgba(255,135,6,1)", }, // }, }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: "rgba(255,135,6,0.3)", }, { offset: 0.6, color: "rgba(255,135,6, 0)", }, ]), }, data: [30,20,30,100,90], }, { type: 'custom', renderItem: (params, api) => { const location = api.coord([api.value(0), api.value(1)]); location[0] = location[0] + wid * 0; const xlocation = api.coord([api.value(0), 0]); xlocation[0] = xlocation[0] + wid * 0; return { type: 'group', children: [{ type: 'CubeLeft', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: xlocation }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#40fbeb' }, { offset: 1, color: '#40fbeb' } ]) } }, { type: 'CubeRight', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: xlocation }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#25dbc9' }, { offset: 1, color: '#25dbc9' } ]) } }, { type: 'CubeTop', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: xlocation }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#84fffb' }, { offset: 1, color: '#84fffb' } ]) } }] } }, color: 'blue', data: y }] };