let xaxisData = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] let yaxisData = [90, 80, 100, 70, 65, 69, 80] const offsetX = 18; const offsetY = 9; // 绘制左侧面 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 - 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: "#1146cc", tooltip: { trigger: "axis", axisPointer: { type: "shadow", }, // backgroundColor: "rgba(255,255,255,0.75)", extraCssText: "box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.3);", textStyle: { fontSize: 14, color: "#000", }, formatter: (params, ticket, callback) => { const item = params[1]; return item.name + " : " + item.value + " 个"; }, }, grid: { left: "1%", right: "0%", top: "16%", bottom: "5%", containLabel: true, }, xAxis: { type: 'category', data: xaxisData, axisLine: { show: false, lineStyle: { width: 1, color: '#545454' } }, axisTick: { show: false }, axisLabel: { fontSize: 16, color: 'rgba(255,255,255,0.7)' } }, yAxis: { type: 'value', nameTextStyle: { color: '#fff', fontWeight: 400, fontSize: 14 }, axisLine: { show: false, lineStyle: { width: 1, color: '#545454' } }, splitLine: { show: true, lineStyle: { type: 'dashed',//线的类型 虚线0 opacity: 0.2//透明度 }, }, axisTick: { show: false }, axisLabel: { fontSize: 16, color: 'rgba(255,255,255,0.7)' }, }, series: [ { type: "custom", renderItem: (params, api) => { const location = api.coord([api.value(0), api.value(1)]); return { type: "group", 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: '#04cee0' }, { offset: 0.5, color: '#03d0e2', }, { offset: 0.95, color: '#0e50cd' }, { offset: 1, color: '#104bca' } ]), }, }, { 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: '#04cee0' }, { offset: 0.5, color: '#03d0e2', }, { offset: 0.95, color: '#0e50cd' }, { offset: 1, color: '#104bca' } ]), }, }, { 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: '#04d0e2' }, }, ], }; }, data: yaxisData, }, { type: "bar", itemStyle: { color: "transparent", }, label: { normal: { show: true, position: 'top', fontSize: 16, color: 'rgba(255,255,255,0.7)', offset: [0, -15], }, }, data: yaxisData, }, ], }; if (option && typeof option === "object") { var index = 0; //播放所在下标 var mTime = setInterval(function () { myChart.dispatchAction({ type: 'showTip', seriesIndex: 0, dataIndex: index }); index++; if (index >= 7) { index = 0; } }, 2800); }