const offsetX = 20 const offsetY = 10 // 绘制左侧面 const CubeLeft = echarts.graphic.extendShape({ shape: { x: 0, y: 0 }, buildPath: function (ctx, shape) { // 会canvas的应该都能看得懂,shape是从custom传入的 const xAxisPoint = shape.xAxisPoint // console.log(shape); const c0 = [shape.x - offsetX, shape.y - offsetY] const c1 = [shape.x + offsetX, shape.y - offsetY] const c2 = [xAxisPoint[0] + offsetX,xAxisPoint[1] + offsetY-10] const c3 = [xAxisPoint[0] - offsetX, xAxisPoint[1] + offsetY-10] 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 = [xAxisPoint[0], xAxisPoint[1]] const c3 = [xAxisPoint[0] + offsetX, xAxisPoint[1] - offsetY] const c4 = [shape.x + offsetX, 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- offsetX/2, shape.y-offsetY-offsetY/2-6] // const c2 = [shape.x + offsetX/2, shape.y-offsetY-offsetY/2-6] // 右点 // const c3 = [shape.x + offsetX, shape.y-offsetY/2-6] // const c4 = [shape.x + offsetX/2, shape.y+offsetY/2-6] // const c5 = [shape.x - offsetX/2, shape.y+offsetY/2-6] // const c6 = [shape.x-offsetX, shape.y-offsetY/2-6] // ctx.moveTo(c1[0], c1[1]) // .lineTo(c2[0], c2[1]) // .lineTo(c3[0], c3[1]) // .lineTo(c4[0], c4[1]) // .lineTo(c5[0], c5[1]) // .lineTo(c6[0], c6[1]).closePath() //椭圆 var k = (offsetX/0.75), h = offsetY/2, x =shape.x, y=shape.y-offsetY; ctx.moveTo(x, y-h) .bezierCurveTo(x+k, y-h, x+k, y+h, x, y+h) .bezierCurveTo(x-k, y+h, x-k, y-h, x, y-h) .closePath() } }) // 绘制底面 const CubeBottom = echarts.graphic.extendShape({ shape: { x: 0, y: 0 }, buildPath: function (ctx, shape) { const xAxisPoint = shape.xAxisPoint //六边形 // const c1 = [shape.x- offsetX/2, xAxisPoint[1]+offsetY/2+2] // const c2 = [shape.x-offsetX, xAxisPoint[1]] // 右点 // const c3 = [shape.x + offsetX, xAxisPoint[1]] // const c4 = [shape.x + offsetX/2, xAxisPoint[1]+offsetY/2+2] // ctx.moveTo(c1[0], c1[1]) // .lineTo(c2[0], c2[1]) // .lineTo(c3[0], c3[1]) // .lineTo(c4[0], c4[1]).closePath() //半个椭圆 var k = (offsetY/0.75), w = offsetX, x =shape.x, y= xAxisPoint[1]; ctx.moveTo(x-w, y) .bezierCurveTo(x-w, y+k, x+w, y+k, x+w, y) .closePath() } }) // 注册三个面图形 echarts.graphic.registerShape('CubeLeft', CubeLeft) echarts.graphic.registerShape('CubeBottom', CubeBottom) echarts.graphic.registerShape('CubeTop', CubeTop) const VALUE = [750, 600, 500, 400, 300] const data=[[750, 600, 500, 400, 300],[780, 650, 400, 450, 200]] let list=[] data.forEach((ele,index)=>{ list.push({ type: 'custom', renderItem: (params, api) => { const location = api.coord([api.value(0), api.value(1)]) return { type: 'group', x: -10*index+index*60, children: [ { type: 'CubeLeft', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#8DC21F' }, { offset: 1, color: '#00A1A3' } ]) } }, { type: 'CubeTop', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#8DC21F' }, { offset: 1, color: '#70A600' } ]) } }, { type: 'CubeBottom', shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) }, style: { fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#00A1A3' }, { offset: 1, color: '#00A1A3' } ]) } }, ] } }, data: ele },) }) const option = { backgroundColor: 'rgba(0,0,0, .6)', tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, // formatter: function (params) { // const item = params[1] // return item.name + ' : ' + item.value // } }, grid: { left: '5%', right: '5%', top: '10%', bottom: '10%', containLabel: true }, xAxis: { type: 'category', data: ['影视', '高端装备', '计算机', '总集成', '3d打印'], axisLine: { show: true, lineStyle: { width: 1, color: '#CEDDF2' } }, axisTick: { show: false }, axisLabel: { fontSize: 10 } }, yAxis: { type: 'value', axisLine: { show: false, lineStyle: { width: 2, color: '#CEDDF2' } }, splitLine: { show: true, lineStyle: { color: '#2A353F', type: 'dashed' } }, axisTick: { show: false }, axisLabel: { fontSize: 12 } }, dataZoom: [{ type: 'slider', show: false, realtime: true, startValue: 0, endValue: 3, // 初始显示index0-30的数据,可根据你的数据量设置 filterMode: 'none', }, ], series: list }