let name=['测试一','测试二','测试三','测试四','测试五','测试六','测试七','测试八','测试九']; let value =[1,45,24,6,37,42,45,67,9]; let value1 =[21,35,44,61,74,2,45,47,92]; let toolTims = null const offsetX = 8; const offsetY = 4; // 绘制左侧面 const CubeLeft = echarts.graphic.extendShape({ shape: { x: 0, y: 0, }, buildPath: function (ctx, shape) { const xAxisPoint = shape.xAxisPoint; const c0 = [shape.x, shape.y]; const c1 = [shape.x - offsetX, shape.y - offsetY]; const c2 = [xAxisPoint[0] - offsetX, xAxisPoint[1] - offsetY]; const c3 = [xAxisPoint[0], 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 = [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, shape.y]; const c2 = [shape.x + offsetX, shape.y - offsetY]; //右点 const c3 = [shape.x, shape.y - offsetX]; 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(); }, }); // 注册三个面图形 echarts.graphic.registerShape('CubeLeft', CubeLeft); echarts.graphic.registerShape('CubeRight', CubeRight); echarts.graphic.registerShape('CubeTop', CubeTop); // 主体 option = { backgroundColor: '#333', legend: { icon: "circle", left: '20px', top: '10px', itemWidth: 16, itemHeight: 16, itemGap: 20, textStyle: { fontSize: 14, color: "#fff", }, data: ["累计作业", "在施"], }, title: { text: '', left: 'center', textStyle: { color: '#2B7BD6', }, }, tooltip: { trigger: 'item', }, grid: { // width: "95%", // height: "95%", top: "8%", left: "5%", right: "5%", bottom: "5%", containLabel: true, }, xAxis: { type: 'category', data: name, // X axisLine: { show: true, lineStyle: { // width: 1, color: '#2B7BD6', }, }, axisTick: { show: false, }, axisLabel: { fontSize: 14, interval: 0, }, axisLine: { show: true, lineStyle: { color: 'rgba(42, 130, 228, 1)', }, }, axisLabel: { textStyle: { color: '#FFF', //更改坐标轴文字颜色 fontSize: 12 //更改坐标轴文字大小 } } }, yAxis: { name: '', type: 'value', axisLine: { show: true, lineStyle: { // width: 1, color: '#2B7BD6', }, }, splitLine: { show: true, lineStyle: { type:'dashed', color: 'rgba(20, 153, 255, 1)', }, }, axisTick: { show: false, }, axisLabel: { fontSize: 14, }, axisLabel: { textStyle: { color: '#FFF', //更改坐标轴文字颜色 fontSize: 12 //更改坐标轴文字大小 } } }, series: [ // 柱体 { name: '累计作业', type: 'custom', stack: "Ad", renderItem: (params, api) => { const location = api.coord([api.value(0), api.value(1)]); return { type: 'group', x: -20, 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: 'rgba(2, 93, 196, 1)', }, { offset: 1, color: 'rgba(0, 155, 217, 1)', }, ]), }, }, { type: 'CubeRight', 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: 'rgba(2, 93, 196, 1)', }, { offset: 1, color: 'rgba(115, 246, 255, 1)', }, ]), }, }, { 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: 'rgba(28, 240, 255, 1)', }, { offset: 1, color: 'rgba(201, 251, 255, 1)', }, ]), }, }, ], }; }, data: value, }, // 柱体 { name: '在施', type: 'custom', stack: "Ad", renderItem: (params, api) => { const location = api.coord([api.value(0), api.value(1)]); return { type: 'group', x: 1, 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: 'rgba(10, 148, 72, 1)', }, { offset: 1, color: 'rgba(11, 255, 136, 1)', }, ]), }, }, { type: 'CubeRight', 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: 'rgba(0, 255, 132, 1)', }, { offset: 1, color: 'rgba(117, 255, 172, 1)', }, ]), }, }, { 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: 'rgba(117, 255, 172, 1)', }, { offset: 1, color: 'rgba(240, 255, 246, 1)', }, ]), }, }, ], }; }, data: value1, }, ], }; // tooltip自动轮播 若使用请做销毁处理 // if (option && typeof option === "object") { // var index = 0; // toolTims = setInterval(function () { // myChart.dispatchAction({ // type: 'showTip', // seriesIndex: 0, // dataIndex: index // }); // index++; // if (index >= 7) { // index = 0; // } // }, 2800); // }