vue3+echarts:Vue中使用echarts从后端获取数据并赋值显示

//由于前后端交互,所以使用axios发送请求
const Count = ref(null); //设备种类数值
const Name = ref(null); //设备种类名称
//设备种类 饼图
const pieChart = () => {
  const getpieChart = echarts.init(document.getElementById("deviceKind"));
  // 创建图标
  getpieChart.setOption({
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "25%",
      right: "right",
      textStyle: {
        color: "rgba(217,215,218,1.000)",
      },
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["40%", "70%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2,
        },
        label: {
          show: false,
          position: "center",
        },
        emphasis: {
          label: {
            show: true,
            fontSize: "40",
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: null,
      },
    ],
  });
  //echarts异步加载,获取后端数据
  CenterOverviewType().then((res) => {
    if (res.status === 200) {
      //将二维数组拆分
      Count.value = res.data.data.deviceTypeCount;
      Name.value = res.data.data.deviceTypeName;
      for (const key in Count.value) {
        deviceChartsData.push({
          name: Name.value[key],
          value: Count.value[key],
        });
      }
      //饼图重新赋值data
      getpieChart.setOption({
        series: [
          {
            data: deviceChartsData, //赋值
          },
        ],
      });
    }
  });
};

上一篇文章,

uniapp踩坑之项目:简易版不同角色显示不一样的tabbar和页面-CSDN博客文章浏览阅读29次。uniapp踩坑之项目:简易版不同角色显示不一样的tabbar和页面。在uni_modules文件夹创建底部导航cc-myTabbar文件夹,在cc-myTabbar文件夹创建components文件夹,在components文件夹创建cc-myTabbar.vue组件。显示第几个tabbar,0是首页 1是财务 2是司机。pages下创建三个不同用户身份的“我的”页面。在utils文件夹创建tabBar.js。pages.json里指定路径。在单页面引入底部导航组件。https://blog.csdn.net/weixin_43928112/article/details/136041617

最近更新

  1. TCP协议是安全的吗?

    2024-02-08 15:28:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-08 15:28:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-08 15:28:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-08 15:28:02       18 阅读

热门阅读

  1. 系统架构22 - 软件架构设计(1)

    2024-02-08 15:28:02       31 阅读
  2. 【C/C++ 16】C++11线程库

    2024-02-08 15:28:02       30 阅读
  3. 前端bug手册

    2024-02-08 15:28:02       31 阅读
  4. react中的diff算法

    2024-02-08 15:28:02       32 阅读
  5. 线程和进程的区别及基础线程创建

    2024-02-08 15:28:02       31 阅读
  6. pandas dataframe写入excel的多个sheet页面

    2024-02-08 15:28:02       34 阅读
  7. Debian系统中挂载一个数据盘

    2024-02-08 15:28:02       31 阅读
  8. 有道论文翻译接口,python版和lua版

    2024-02-08 15:28:02       37 阅读
  9. [Android] Client->NuPlayer

    2024-02-08 15:28:02       31 阅读
  10. work day7

    2024-02-08 15:28:02       30 阅读
  11. 【mybatis自动治愈插件】

    2024-02-08 15:28:02       31 阅读
  12. LeetCode 二叉树/n叉树的解题思路

    2024-02-08 15:28:02       37 阅读
  13. Mockito测试框架中的方法详解

    2024-02-08 15:28:02       32 阅读