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

el-table 的单元格 + 图表 + 排序

<el-table border :data="tableDataThree" height="370px" style="width: 100%">
   <el-table-column :key="activeName + '8'" width="50" type="index" label="序号" align="center"></el-table-column>
      <el-table-column :key="activeName + '9'" width="100" prop="cityName" label="市" align="center"></el-table-column>
      <el-table-column :key="activeName + '10'" label="数据" align="center">
            <el-table-column sortable prop="totalCenterMoney" label="总额(万元)" align="center">
                <template slot-scope="scope">
                    <FormCharts :tableDataThree="tableDataThree" :list="scope.row" type="totalCenterMoney" :value="scope.row.totalCenterMoney" />
                </template>
          </el-table-column>
     </el-table-column>
</el-table>

表格中的图标 echarts 

<template>
  <div class="echart-box" ref="echartBoxRef"></div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
import "echarts-liquidfill";

export default {
  props: ["tableDataThree","value","type","color"],
  data() {
    return {
      echartBoxRef: "",
      dataList: [],
      dataNumber: [],
      myChart: "",
      maxTotalCenterMoney:0
    };
  },
  mounted() {
    this.init();
  },
  watch:{
    value: {
      handler(newval, oldval) {
        this.$nextTick(() => {
          this.init()
        })
      },
      immediate:true,
      deep:true
    }
  },
  methods: {
    init() {
      let typpe = this.type
      this.tableDataThree.forEach((e,i) => {  
        // 初始化最大值为数组中的第一个元素(或更小的值以避免未定义错误)  
        this.maxTotalCenterMoney = this.tableDataThree[0] ? this.tableDataThree[0].typpe : 0;  
    
        // 遍历数组以找到每个字段的最大值  
        this.tableDataThree.forEach(item => {  
            if (item.typpe > this.maxTotalCenterMoney) {  
              this.maxTotalCenterMoney = item.typpe;  
            }  
        }); 
      })

      this.myChart = echarts.init(this.$refs.echartBoxRef); // 图标初始化
        if(this.color == '1'){
          this.myChart.setOption({  
              xAxis: {
                  type: "value",
                  show: false,
                  max: this.maxTotalCenterMoney
              },
              yAxis: {
                  type: "category",
                  show: false
              },
              series: [{
                  data: [this.value],
                  type: "bar",
                  barWidth: "10%",
                  showBackground: true,
                  backgroundStyle: {
                      color: '#dce0ee',
                      borderRadius:5
                  },
                  label: {
                    show: true,
                    position: [0, -10],   //value的位置
                    color: '#000', //值的颜色
                    fontSize: 10,
                  },
                  itemStyle: {
                      color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                          { offset: 1, color: "#6d9cd5" },
                          { offset: 0, color: "#a8c9e6" }
                      ]),
                      barBorderRadius: [2, 2, 2, 2],
                  }
              }]
          });  
          window.addEventListener('resize', () => {  
              this.myChart.resize();  
          }); 
        }else{
          this.myChart.setOption({  
              xAxis: {
                  type: "value",
                  show: false,
                  max: this.maxTotalCenterMoney
              },
              yAxis: {
                  type: "category",
                  show: false
              },
              series: [{
                  data: [this.value],
                  type: "bar",
                  barWidth: "10%",
                  showBackground: true,
                  backgroundStyle: {
                      color: '#dee2ef',
                      borderRadius:5
                  },
                  label: {
                      normal: {
                          show: true,
                          position: [0, -10],   //value的位置
                          color: '#000', //值的颜色
                          fontSize: 10,
                      }
                  },
                  itemStyle: {
                      color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                          { offset: 1, color: "#8894c4" },
                          { offset: 0, color: "#bfc6e4" }
                      ]),
                      barBorderRadius: [2, 2, 2, 2],
                  }
              }]
          });  
          window.addEventListener('resize', () => {  
              this.myChart.resize();  
          });  
        }
    },
  }
};
</script>
<style lang="scss" scoped>
.echart-box {
  width: 180px;
  height: 50px;
  margin-top: 10px;
  margin-bottom: -15px;
}
</style>

参考文档:

实现el-table中嵌套echarts图表以及柱条渐变_el-table-v2+echarts-CSDN博客


http://www.kler.cn/news/307293.html

相关文章:

  • 动手学深度学习(pytorch土堆)-03常见的Transforms
  • 图论篇--代码随想录算法训练营第五十六天打卡| 108. 冗余连接,109. 冗余连接II
  • 【SQL】百题计划:SQL排序Order by的使用。
  • Flutter Error: Type ‘UnmodifiableUint8ListView‘ not found
  • 刷题DAY36
  • 初中生物--5.单细胞生物
  • VuePress搭建文档网站/个人博客(详细配置)主题配置-导航栏配置
  • 【开源免费】基于SpringBoot+Vue.JS企业客户管理系统(JAVA毕业设计)
  • Linux命令:文本处理工具sed详解
  • django中F()和Q()的用法
  • 保姆级离线+windows环境+大模型前端UI安装(二)
  • 基于Spring Boot的停车场管理系统的设计与实现
  • 【STL】 set 与 multiset:基础、操作与应用
  • Vue路由配置、网络请求访问框架项目、element组件介绍学习
  • 数据库连接池与Druid【后端 16】
  • STM32 HAL freertos零基础(十)软件定时器
  • Renesas R7FA8D1BH (Cortex®-M85)控制ISLS29035
  • Unity-Transform类-父子关系
  • 五、(JS)window中的定时器
  • PhotoZoom Pro / Classic 9.0.2激活版安装激活图文教程
  • 栈与队列(c语言实现)
  • GAMES101(2~3作业)
  • 【系统架构设计师】单例模式(Singleton Pattern)
  • PCIe进阶之TL:Common Packet Header Fields TLPs with Data Payloads Rules
  • MYSQL数据库基础篇——MYSQL的安装与使用
  • Go中如何找到哪里依赖了某个module,如何找到所有module的最大GoVersion
  • 【UE5 C++课程系列笔记】02——创建C++类的三种方式
  • 如何快速整理生成python项目依赖的库,提升自动化部署效率
  • jdk相关介绍
  • 【Linux下的cpp】编译调试(gcc、g++、gdb)