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)
相关推荐
VisuperviReborn几秒前
打造自己的前端监控---前端流量监控
前端·设计模式·架构
前端Hardy7 分钟前
Python是怎么将Vue项目打包成桌面端应用程序的?看这篇就够了
前端·javascript·python
Spider_Man19 分钟前
物料区的“超市大冒险”:组件、遥控器与快乐星球的奇遇记 🛒🦄
前端·低代码·typescript
uppp»20 分钟前
echarts在前后端分离项目中的实践与应用
前端·javascript·echarts
之梦22 分钟前
Electron + Vue3开源跨平台壁纸工具实战(九)子进程服务(2)
前端·electron
三小河22 分钟前
css 中 inset属性 以及简单实现spinner
前端
小趴菜_23 分钟前
手把手教你用 Vue3 + LogicFlow 打造流程编排系统
前端·vue.js
MapleWan3206324 分钟前
关于统一地图组件的一些实践与思考
前端·开源
袁煦丞25 分钟前
Bitwarden+cpolar让隐私真正属于自己:cpolar内网穿透实验室第516个成功挑战
前端·程序员·远程工作
前端灵派派25 分钟前
electron窗口管理封装和页面通讯
前端·electron