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

javascript 复制代码
<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

html 复制代码
<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博客

相关推荐
Bob99985 分钟前
电脑浏览器访问华为路由器报错,无法访问路由器web界面:ERR_SSL_VERSION_OR_CIPHER_MISMATCH 最简单的解决办法!
开发语言·javascript·网络·python·网络协议·华为·ssl
B.-2 小时前
Remix 学习 - @remix-run/react 中主要的 hooks
前端·javascript·学习·react.js·web
计算机学姐2 小时前
基于微信小程序的食堂点餐预约管理系统
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
2302_802836162 小时前
JS考核答案
javascript
罗_三金3 小时前
微信小程序读写NFC标签(实现NFC标签快速拉起小程序)实战
前端·javascript·微信小程序·小程序
双普拉斯3 小时前
微信小程序实现转盘抽奖,可以自定义编辑奖项列表
javascript·微信小程序·小程序
徐同保3 小时前
el-table的树形结构结合多选框使用,实现单选父子联动,全选,反选功能
javascript
J总裁的小芒果3 小时前
vue3-print打印eletable某一行的数据
javascript·vue.js·elementui
大大。3 小时前
el-input 只能输入数字和一个小数点,或者只能输入正整数
前端·javascript·vue.js
盼盼盼4 小时前
如何避免在使用 Context API 时出现状态管理的常见问题?
前端·javascript·react.js