立体柱状图和折线图双轴

描述:当前是关于Echarts图表中的 示例。
 
            // 柱状图的宽度,y是x的一半
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
      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()
   }
})
// // 绘制底面
const CubeBottom = echarts.graphic.extendShape({
   shape: {
      x: 10,
      y: 10
   },
   buildPath: function (ctx, shape) {
      const xAxisPoint = shape.xAxisPoint
      const c1 = [xAxisPoint[0] - offsetX, xAxisPoint[1] - offsetY]
      const c2 = [xAxisPoint[0], xAxisPoint[1]] // 右点
      const c3 = [xAxisPoint[0] + offsetX, xAxisPoint[1] - offsetY]
      const c4 = [xAxisPoint[0], xAxisPoint[1] - offsetX]
      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)
echarts.graphic.registerShape('CubeBottom', CubeBottom)
const dataX = [1,2,3,4,6,7]
const barData = [233,4,5,6,132,1]
const lineData = [123,435,6,31,4]
option = {
   //你的代码
   backgroundColor: '#031a40',
   legend: {
      show: true,
      right: 30,
      top: 10,
      itemGap: 30,
      itemWidth: 20,
      itemHeight: 10,
      data: ['时长', '百分比'],
      textStyle: {
         fontSize: 18,
         color: '#ffffff'
      }
   },
   color: ['#097dc0', '#26D6D7'],
   tooltip: {
      trigger: 'axis',
      textStyle: {
         fontSize: 18 // 字体大小
      },
      axisPointer: {
         type: 'shadow'
      }
   },
   grid: {
      top: '20%',
      left: '3%',
      right: '3%',
      bottom: '5%',
      containLabel: true
   },
   xAxis: {
      type: 'category',
      data: dataX,
      axisLine: {
         show: true,
         lineStyle: {
            width: 1,
            color: 'rgba(239, 247, 253, .1)'
         }
      },
      axisTick: {
         show: false
      },
      axisLabel: {
         fontSize: 16,
         color: '#E7FCFF',
         margin: 20
      }
   },
   yAxis: [
      {
         type: 'value',
         name:'时长:天',
         nameGap: 30,
         nameTextStyle: {
            color: '#ffffff',
            fontWeight: 400,
            fontSize: 16
         },
         axisLine: {
            show: false,
            lineStyle: {
               width: 1,
               color: 'rgba(239, 247, 253, .1)'
            }
         },
         splitLine: {
            show: false,
            lineStyle: {
               color: 'rgba(239, 247, 253, .1)'
            }
         },
         axisTick: {
            show: false
         },
         axisLabel: {
            fontSize: 16,
            color: '#E7FCFF'
         },
         min: 0,
         // max: Math.ceil(Math.max.apply(null, dataX) / 5) * 5,
         // interval: Math.ceil(Math.max.apply(null, dataX) / 5)
      },
      {
         type: 'value',
         name:'%',
         nameGap: 30,
         nameTextStyle: {
            color: '#ffffff',
            fontWeight: 400,
            fontSize: 16
         },
         axisLine: {
            show: false,
            lineStyle: {
               width: 1,
               color: 'rgba(239, 247, 253, .1)'
            }
         },
         splitLine: {
            show: false,
            lineStyle: {
               color: 'rgba(239, 247, 253, .1)'
            }
         },
         axisTick: {
            show: false
         },
         axisLabel: {
            fontSize: 16,
            color: '#E7FCFF'
         }
      }
   ],
   series: [
      {
         name: '时长',
         type: 'custom',
         renderItem: (params, api) => {
            const location = api.coord([api.value(0), api.value(1)])
            return {
               type: 'group',
               x: 0,
               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: '#24a7ed'
                           },
                           {
                              offset: 1,
                              color: '#24a7ed'
                           }
                        ]),
                        stroke: 'rgba(3, 25, 63, .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: '#097dc0'
                           },
                           {
                              offset: 1,
                              color: '#097dc0'
                           }
                        ]),
                        stroke: 'rgba(3, 25, 63, .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: '#148cd2'
                           },
                           {
                              offset: 1,
                              color: '#148cd2'
                           }
                        ]),
                        stroke: 'rgba(3, 25, 63, .1)', //边框颜色
                     }
                  }
               ]
            }
         },
         data: barData
      },
      {
         name: '百分比',
         type: 'line',
         showSymbol: true,
         smooth: true,
         symbol: 'rect',
         symbolSize: 8,
         yAxisIndex: 1,
         itemStyle: {
            color: '#01EEFD'
         },
         lineStyle: {
            width: 3
         },
         areaStyle: {
           normal: {
             color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
               offset: 0,
               color: 'rgba(67, 239, 255, .3)',
             },
             {
               offset: 1,
               color: 'rgba(1, 17, 49, .3)',
             }
             ]),
           },
         },
         data: lineData
      }
   ]
}