当前位置: 首页 > news >正文

echarts多组堆叠柱状图

一、效果图

二、代码实现

1、创建容器

 <el-card class="box-card"><div slot="header" class="clearfix"><span>课堂学习</span></div><div id="class-learning" style="height: 360px"></div></el-card>

2、初始化实例

 created () {this.$nextTick(()=>{this.initCharts()});},
 getAnalysisData(result){let hasData = result != null && JSON.stringify(result) != '{}';this.initCharts(hasData);},
 initCharts(hasData){this.chartInstances.forEach(chart =>{if(chart != null & chart != '' && chart != undefined){chart.dispose();}})this.chartInstances = [echarts.init(document.getElementById('class-learning')).setOption(this.learningOption),]}

3、设置柱状图样式和内容

 learningOption : {title: {text: '课堂学习各指标人数分布',left: '49%',textAlign: 'center',},// legend的data内容与series中的数据name名称要保持一致 图例的名称和颜色才会显示legend: {data: ["专注听讲", "认真思考","积极参与","内容掌握度"],bottom: "20px",},xAxis: {type: 'category',data: ['语文', '数学', '英语']},yAxis: {type:'value',// axisLabel: {//     show: true,// 显示x轴标签//     formatter: `{value}%`,//     interval: 0// },// axisTick:{//     show: true //不显示坐标轴刻度线// },axisLine: {show: true, //显示坐标轴线},splitLine: {     //网格线"show": false},// y轴刻度标签设置 对value整除得到list数组的下标 再显示到y轴标签上axisLabel: {formatter: (value) => {const list = ['差', '较差', '','较好','', '好']return list[value/20]}},},series: [//堆叠柱状图 堆叠在同一个柱子上要设置一样的stack值(可以是数字可以是字符可以是汉字){name: '专注听讲差',type: 'bar',stack: '1',// 鼠标停留时高亮显示 其余内容虚化emphasis: {focus: 'series'},// 柱状图的说明标签显示 标签颜色为黑色 单位为%label: {show: true,color:'black',formatter: '{c}%',//单位},// 柱子带边框itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [8,33,12]},{name: '专注听讲',type: 'bar',stack: '1',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%', //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [32,20,32]},{name: '专注听讲较好',type: 'bar',stack: '1',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%', //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [41,26,51]},{name: '专注听讲好',type: 'bar',stack: '1',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%', //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [19,21,5]},// stack值不同 则是另外一个柱子{name: '认真思考差',type: 'bar',stack: '2',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [15,17,8]},{name: '认真思考',type: 'bar',stack: '2',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [28,45,26]},{name: '认真思考较好',type: 'bar',stack: '2',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [34,24,28]},{name: '认真思考好',type: 'bar',stack: '2',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [23,14,38]},{name: '积极参与差',type: 'bar',stack: '3',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [22,9,5]},{name: '积极参与',type: 'bar',stack: '3',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [25,40,46]},{name: '积极参与较好',type: 'bar',stack: '3',// barGap: 10,emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [48,34,35]},{name: '积极参与好',type: 'bar',stack: '3',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [5,17,14]},{name: '内容掌握度差',type: 'bar',stack: '4',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [9,22,25]},{name: '内容掌握度',type: 'bar',stack: '4',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [41,26,25]},{name: '内容掌握度较好',type: 'bar',stack: '4',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [48,42,35]},{name: '内容掌握度好',type: 'bar',stack: '4',emphasis: {focus: 'series'},label: {show: true,color:'black',formatter: '{c}%' //单位},itemStyle: {normal: {borderColor:'#fff',borderWidth: 1,}},data: [2,10,15]}],color:['#335899','#3f6ab7','#7991ce','#b3bedf','#a0460d','#ed7d31','#f4b183','#f8cbad','#bf9000','#ffc000','#ffd966','#ffe699','#548235','#70ad47','#a9d18e','#c5e0b4']},

http://www.lryc.cn/news/434642.html

相关文章:

  • 打造安心宠物乐园:EasyCVR平台赋能猫咖/宠物店的智能视频监控解决方案
  • springboot请求传参常用模板
  • HTML/CSS/JS学习笔记 Day4(HTML--C3 表格)
  • WPF中创建横向的ListView
  • A表和B表公共元素产生链表C
  • Rust运算符
  • Oracle rman 没有0级时1级备份和0级大小一样,可以用来做恢复 resetlogs后也可以
  • idea中配置Translation插件完成翻译功能
  • 如何看待:低代码开发平台的兴起无需经验?
  • OpenCV-轮廓检测
  • vue页面使用自定义字体
  • C++——list常见函数的使用和模拟实现(2)
  • C 标准库 - `<float.h>`
  • 【机器人工具箱Robotics Toolbox开发笔记(二)】Matlab中机器人工具箱的下载与安装
  • ROS2 Nav2 - Smac 规划器
  • LabVIEW环境中等待FPGA模块初始化完成
  • 手机TF卡格式化后数据恢复:方法、挑战与预防措施
  • ceph对象存储使用的一些思考
  • 单词排序C++实现
  • 828华为云征文 | Flexus X 实例服务器网络性能深度评测
  • STL —heap算法源码刨析 make_heap、push_heap、pop_heap、sort_heap操作分析
  • 走进低代码表单开发(一):可视化表单数据源设计
  • 简单好用的OCR API
  • c++的拷贝构造函数和赋值函数
  • 什么自动猫砂盆才适合旅游党?4个选购技巧统统告诉你!
  • 算法知识点————双指针【删除重复元素】【反转链表】
  • 建造者模式builder
  • IEC103设备数据 转 IEC61850项目案例
  • 438.找到字符串中所有字母异位词
  • Microsoft SC-100: Microsoft 网络安全架构师