echarts3D柱状图多个和一个

在这里插入图片描述

<template>
  <a-card title="月度故障业务平均恢复时长" iconname="el-icon-data-analysis">
    <div class="chart-container">
      <a-row :gutter="16">
        <a-col :span="12"><div ref="chart" class="chart" style="height: 600px; width: 600px" /></a-col>
        <a-col :span="12"><div ref="charttwo" style="height: 600px; width: 600px"></div></a-col>
      </a-row>
      
      
    </div>
  </a-card>
</template>

<script>
import echarts from 'echarts';
export default {
  data() {
    return {
      statusChart: null
    };
  },
  mounted() {
    this.initChart();
    this.initChartTwo();
    // 根据窗口变化自动调节图表大小
    // window.addEventListener('resize', this.changeSize)
  },
  beforeDestroy() {
    // console.log('销毁')
    // this.statusChart && this.statusChart.dispose()
    // window.removeEventListener('resize', this.changeSize)
  },
  methods: {
    // 自适应宽高
    // changeSize() {
    //     this.statusChart.resize()
    // },
    initChart() {
      //调用:
      var changeBar = echarts.init(this.$refs.chart);
      let option = this.getSolidOption([0, 0, 260, 30, 30, 30], [0, 182, 191, 30, 0, 30], [0, 182, 191, 0, 40, 40]);
      console.log(option);
      changeBar.setOption(option);
    },
    initChartTwo() {
      this.statusChart = echarts.init(this.$refs.charttwo);
      var colorArr = ['#0C628C', '#3887D5', '#2570BB'];
      var color = {
        type: 'linear',
        x: 0,
        x2: 1,
        y: 0,
        y2: 0,
        colorStops: [
          {
            offset: 0,
            color: colorArr[0]
          },
          {
            offset: 0.5,
            color: colorArr[0]
          },
          {
            offset: 0.5,
            color: colorArr[1]
          },
          {
            offset: 1,
            color: colorArr[1]
          }
        ]
      };
      var barWidth = 30;
      const xAxisData = ['区域1', '区域2', '区域3', '区域4', '区域5', '区域6', '区域7', '区域8', '区域9'];
      var data1 = [6, 7, 3, 11, 33, 38, 22, 55, 66];
      var bottomData = [1, 1, 1, 1, 1, 1, 1, 1, 1];
      var topData = [100, 100, 100, 100, 100, 100, 100, 100, 100];
      // 指定图表的配置项和数据
      const option = {
        backgroundColor: '#242640',
        // backgroundColor: 'rgba(0,0,0,0)',
        tooltip: {
          trigger: 'axis',
          formatter: function (params) {
            var str = params[0].name + ':';
            params.filter(function (item) {
              if (item.componentSubType == 'bar') {
                str += '<br/>' + item.seriesName + ':' + item.value;
              }
            });
            return str;
          }
        },
        grid: {
          x: '7%',
          x2: '0%',
          y: '15%',
          y2: '15%'
        },
        xAxis: {
          type: 'category',
          data: xAxisData,

          // 更改坐标轴颜色
          axisLine: {
            lineStyle: {
              color: '#455B77'
            },
            onZero: false
          },
          // x轴的字体样式
          axisLabel: {
            interval: 0,
            textStyle: {
              color: '#c0e6f9', // 更改坐标轴文字颜色
              fontSize: 14, // 更改坐标轴文字大小
              fontFamily: 'MicrosoftYaHei'
            },
            // X轴lable的处理函数,如果x轴的lable有空格,比如:['AM点检 异常', 'PM巡检 异常', 'PM保养 异常'],这里会以空格为分割,显示两行
            formatter: function (params) {
              return params.split(' ').join('\n');
              //                console.log(' formatter',params);
            }
          }
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value}',
            textStyle: {
              color: this.fontColorY, // 更改坐标轴文字颜色
              fontSize: 12, // 更改坐标轴文字大小
              fontFamily: 'MicrosoftYaHei'
            }
          },
          // 更改坐标轴颜色
          axisLine: {
            lineStyle: {
              color: '#657CA8'
            }
          },
          // 网格线
          splitLine: {
            // 网格线
            lineStyle: {
              type: 'solid',
              with: 0.5,
              color: this.borderColor
            }
          }
        },
        series: [
          // 数据低下的圆片
          {
            name: '',
            type: 'pictorialBar',
            symbolOffset: ['0%', '50%'],
            symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
            z: 12,
            symbol: 'diamond',
            itemStyle: {
              opacity: 1,
              color: color
              // color: 'transparent'
            },
            data: bottomData
          },
          // 数据的柱状图
          {
            name: '',
            type: 'bar',
            barWidth: barWidth,
            itemStyle: {
              // lenged文本
              opacity: 1, // 这个是 透明度
              color: color
            },

            data: data1
          },
          // 数据顶部的样式
          {
            name: '',
            type: 'pictorialBar',
            symbol: 'diamond',
            symbolOffset: ['0%', '-50%'],
            symbolSize: [barWidth, 10],
            z: 12,
            itemStyle: {
              normal: {
                opacity: 1,
                color: colorArr[2],
                label: {
                  show: true, // 开启显示
                  position: 'top', // 在上方显示
                  textStyle: {
                    // 数值样式
                    color: '#FFFFFF',
                    fontSize: 12,
                    top: 50
                  }
                }
              }
            },
            symbolPosition: 'end',
            data: data1
          }
        ]
      };
      this.statusChart.setOption(option);
    },
    // 立体多柱状图
    getSolidOption(data1, data2, data3) {
      // 月份坐标轴
      var nowMonth = new Date().getMonth() + 1;
      var lineXAxisData = [];
      for (var i = 5; i >= 0; i--) {
        var month = nowMonth - i;
        if (month < 1) {
          lineXAxisData.push(month + 12 + '月');
        } else {
          lineXAxisData.push(month + '月');
        }
      }
      var colors = [
        {
          type: 'linear',
          x: 0,
          x2: 1,
          y: 0,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: '#27afc7'
            },
            {
              offset: 0.5,
              color: '#27afc7'
            },
            {
              offset: 0.5,
              color: '#50d9cf'
            },
            {
              offset: 1,
              color: '#50d9cf'
            }
          ]
        },
        {
          type: 'linear',
          x: 0,
          x2: 1,
          y: 0,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: '#41affa'
            },
            {
              offset: 0.5,
              color: '#41affa'
            },
            {
              offset: 0.5,
              color: '#80d2fa'
            },
            {
              offset: 1,
              color: '#80d2fa'
            }
          ]
        },
        {
          type: 'linear',
          x: 0,
          x2: 1,
          y: 0,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: '#a6a0fa'
            },
            {
              offset: 0.5,
              color: '#a6a0fa'
            },
            {
              offset: 0.5,
              color: '#bbbbf9'
            },
            {
              offset: 1,
              color: '#bbbbf9'
            }
          ]
        }
      ];
      var barWidth = 15;
      var constData1 = [];
      var showData1 = [];
      data1.filter(function (item) {
        if (item) {
          constData1.push(1);
          showData1.push(item);
        } else {
          constData1.push(0);
          showData1.push({
            value: 1,
            itemStyle: {
              normal: {
                borderColor: 'rgba(0,0,0,0)',
                borderWidth: 2,
                color: 'rgba(0,0,0,0)'
              }
            }
          });
        }
      });
      var constData2 = [];
      var showData2 = [];
      data2.filter(function (item) {
        if (item) {
          constData2.push(1);
          showData2.push(item);
        } else {
          constData2.push(0);
          showData2.push({
            value: 1,
            itemStyle: {
              normal: {
                borderColor: 'rgba(0,0,0,0)',
                borderWidth: 2,
                color: 'rgba(0,0,0,0)'
              }
            }
          });
        }
      });
      var constData3 = [];
      var showData3 = [];
      data3.filter(function (item) {
        if (item) {
          constData3.push(1);
          showData3.push(item);
        } else {
          constData3.push(0);
          showData3.push({
            value: 1,
            itemStyle: {
              normal: {
                borderColor: 'rgba(0,0,0,0)',
                borderWidth: 2,
                color: 'rgba(0,0,0,0)'
              }
            }
          });
        }
      });
      return {
        backgroundColor: '#242640',
        tooltip: {
          trigger: 'axis',
          formatter: function (params) {
            var str = params[0].axisValue + ':';
            params.filter(function (item) {
              if (item.componentSubType == 'bar') {
                str += '<br/>' + item.seriesName + ':' + item.value;
              }
            });
            return str;
          }
        },
        legend: {
          textStyle: {
            color: "#fff"
        },
          data: ['新增', '删除', '修改']
        },
        grid: {
          left: '3%', //图表距边框的距离
          right: '3%',
          top: '15%',
          bottom: '5%',
          containLabel: true
        },
        xAxis: {
          data: lineXAxisData,
          axisTick: {
            show: false
          },
          axisLine: {
            //x轴线的颜色以及宽度
            show: true,
            lineStyle: {
              color: '#455B77'
              // width: 0,
              // type: "solid"
            }
          },
          axisLabel: {
            interval: 0,
            textStyle: {
              color: '#c0e6f9'
            }
          }
        },
        yAxis: {
          axisTick: {
            show: false
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#455B77' //y轴颜色
            }
          },
          axisLabel: {
            show: false
          },
          splitLine: {
            show: false
          }
        },
        series: [
          {
            z: 1,
            name: '新增',
            type: 'bar',
            barWidth: barWidth,
            barGap: '0%',
            data: data1,
            itemStyle: {
              normal: {
                color: colors[0]
              }
            }
          },
          {
            z: 2,
            name: '新增',
            type: 'pictorialBar',
            data: constData1,
            symbol: 'diamond',
            symbolOffset: ['-100%', '50%'],
            symbolSize: [barWidth, 10],
            itemStyle: {
              normal: {
                color: colors[0]
              }
            },
            tooltip: {
              show: false
            }
          },
          {
            z: 3,
            name: '新增',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: showData1,
            symbol: 'diamond',
            symbolOffset: ['-135%', '-50%'],
            symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
            itemStyle: {
              normal: {
                borderColor: '#8bead4',
                borderWidth: 2,
                color: '#8bead4'
              }
            },
            tooltip: {
              show: false
            }
          },
          {
            z: 1,
            name: '删除',
            type: 'bar',
            barWidth: barWidth,
            data: data2,
            itemStyle: {
              normal: {
                color: colors[1]
              }
            }
          },
          {
            z: 2,
            name: '删除',
            type: 'pictorialBar',
            data: constData2,
            symbol: 'diamond',
            symbolOffset: ['0%', '50%'],
            symbolSize: [barWidth, 10],
            itemStyle: {
              normal: {
                color: colors[1]
              }
            },
            tooltip: {
              show: false
            }
          },
          {
            z: 3,
            name: '删除',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: showData2,
            symbol: 'diamond',
            symbolOffset: ['0%', '-50%'],
            symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
            itemStyle: {
              normal: {
                borderColor: '#96dfff',
                borderWidth: 2,
                color: '#96dfff'
              }
            },
            tooltip: {
              show: false
            }
          },
          {
            z: 1,
            type: 'bar',
            name: '修改',
            barWidth: barWidth,
            data: data3,
            itemStyle: {
              normal: {
                color: colors[2]
              }
            }
          },
          {
            z: 2,
            name: '修改',
            type: 'pictorialBar',
            data: constData3,
            symbol: 'diamond',
            symbolOffset: ['100%', '50%'],
            symbolSize: [barWidth, 10],
            itemStyle: {
              normal: {
                color: colors[2]
              }
            },
            tooltip: {
              show: false
            }
          },
          {
            z: 3,
            name: '修改',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: showData3,
            symbol: 'diamond',
            symbolOffset: ['135%', '-50%'],
            symbolSize: [barWidth - 4, (10 * (barWidth - 4)) / barWidth],
            itemStyle: {
              normal: {
                borderColor: '#d5d2ff',
                borderWidth: 2,
                color: '#d5d2ff'
              }
            },
            tooltip: {
              show: false
            }
          }
        ]
      };
    }
  }
};
</script>
<style lang="scss" scoped>
/deep/.editable-cell {
  position: relative;
}

/deep/.editable-cell-input-wrapper {
  padding-right: 24px;
}
/deep/.editable-cell-text-wrapper {
  padding-right: 24px;
}

/deep/.editable-cell-text-wrapper {
  padding: 5px 24px 5px 5px;
}

/deep/.editable-cell-icon {
  position: absolute;
  right: 0;
  width: 20px;
  cursor: pointer;
}
/deep/.editable-cell-icon-check {
  position: absolute;
  right: 0;
  width: 20px;
  cursor: pointer;
}

/deep/.editable-cell-icon {
  line-height: 18px;
  display: none;
}

/deep/.editable-cell-icon-check {
  line-height: 28px;
}

/deep/.editable-cell:hover .editable-cell-icon {
  display: inline-block;
}

/deep/.editable-cell-icon:hover {
  color: #108ee9;
}
/deep/.editable-cell-icon-check:hover {
  color: #108ee9;
}

/deep/.editable-add-btn {
  margin-bottom: 8px;
}
// .chart-container {
//   width: 600px;
//   height: 600px;
// }
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值