Vue3使用ECharts的自定义堆叠条形图(纵向)

先上效果图

展示区域

html 复制代码
<div id="main" style="height: 300px; width: 100%"></div>

配置信息

每个种类的data数组是number数组,这里我使用的变量是从接口返回的数据,为了方便理解,年度考核的绿色种类,里面的data数组我写死了,可以对照图上顺序自行理解

dataZoom:的配置是能够动态的显示条数据

javascript 复制代码
 var chartDom = document.getElementById('main')
    var myChart = echarts.init(chartDom)
    var option
    option = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      legend: {},
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'value',
        min: 0
      },
      yAxis: {
        type: 'category',
        data: orgNameArr.value
      },
      series: [
        {
          name: '基本资料',
          type: 'bar',
          stack: 'total',
          label: {
            show: true
          },
          emphasis: {
            focus: 'series'
          },
          itemStyle: {
            color: '#165DFF'
          },
          data: basicArr.value
        },
        {
          name: '供热质量',
          type: 'bar',
          stack: 'total',
          label: {
            show: true
          },
          emphasis: {
            focus: 'series'
          },
          itemStyle: {
            color: '#14C9C9'
          },
          data: heatArr.value
        },
        {
          name: '设备维护',
          type: 'bar',
          stack: 'total',
          label: {
            show: true
          },
          emphasis: {
            focus: 'series'
          },
          itemStyle: {
            color: '#F7BA1E'
          },
          data: enqiudArr.value
        },
        {
          name: '应急响应',
          type: 'bar',
          stack: 'total',
          label: {
            show: true
          },
          emphasis: {
            focus: 'series'
          },
          itemStyle: {
            color: '#2817EA'
          },
          data: emrresArr.value
        },
        {
          name: '年终考核',
          type: 'bar',
          stack: 'total',
          label: {
            show: true
          },
          itemStyle: {
            color: '#5DC47F'
          },
          emphasis: {
            focus: 'series'
          },
          // data: yearArr.value
          data: [10, 20, 30, 40]
        }
      ],
      dataZoom: [
        {
          type: 'slider',
          show: true,
          yAxisIndex: [0]
        },
        {
          type: 'inside',
          yAxisIndex: [0]
        }
      ]
    }
    option && myChart.setOption(option)
相关推荐
星哥说事1 分钟前
跨平台开源笔记神器,用DeepSeek写笔记 , 效率翻倍
前端
喜欢你,还有大家29 分钟前
FTP文件传输服务
linux·运维·服务器·前端
该用户已不存在33 分钟前
你没有听说过的7个Windows开发必备工具
前端·windows·后端
Bi44 分钟前
Dokploy安装和部署项目流程
运维·前端
普通网友1 小时前
前端安全攻防:XSS, CSRF 等防范与检测
前端·安全·xss
携欢1 小时前
PortSwigger靶场之Reflected XSS into attribute with angle brackets HTML-encoded通关秘籍
前端·xss
小爱同学_1 小时前
React知识:useState和useRef的使用
前端·react.js
再学一点就睡1 小时前
双 Token 认证机制:从原理到实践的完整实现
前端·javascript·后端
wallflower20201 小时前
滑动窗口算法在前端开发中的探索与应用
前端·算法
蚂蚁绊大象1 小时前
flutter第二话题-布局约束
前端